1

行の列を選択するとオーバーライドされたメソッドが呼び出されるテーブルビューがあります

- (void)selectWithFrame:(NSRect)inCellFrame inView:(NSView *)inControlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength {
  // here do some text positioning
         [super selectWithFrame:inCellFrame inView:inControlView editor:textObj delegate:anObject start:selStart length:selLength];
}

また、セルのフィールド エディターを次のように返します。

- (NSTextView *)fieldEditorForView:(NSView *)inControlView {
   MYTextView* fieldEditor = [[[MYTextView alloc] initWithFrame:NSZeroRect] autorelease];
   return fieldEditor;
}

セルが選択されると、セル内のテキストの属性が変更されます。同様に、フォントサイズ、フォントフェイス、フォントスタイルなどがそれに応じて変化します。テキストが選択モードになっているときは、それを制御できないようです。選択後もフォント プロパティを変更したくありません。このテキスト属性の変更を回避するにはどうすればよいですか?

4

1 に答える 1

1

メソッドを呼び出した後-[super selectWithFrame:...]、テキストプロパティへの変更が反映されます。解決策は次のとおりです。

- (void)selectWithFrame:(NSRect)inCellFrame
                 inView:(NSView *)inControlView
                 editor:(NSText *)textObj
               delegate:(id)anObject
                  start:(NSInteger)selStart
                 length:(NSInteger)selLength {
    // here do some text positioning

    [super selectWithFrame:inCellFrame
                    inView:inControlView
                    editor:textObj
                  delegate:anObject
                     start:selStart
                    length:selLength];

    NSMutableAttributedString* text = [textObj textStorage];

    NSMutableParagraphStyle *alignmentStyle = [[NSParagraphStyle defaultParagraphStyle] autorelease];
    [alignmentStyle setAlignment:NSLeftTextAlignment];

    NSDictionary* attributes = [NSMutableDictionary dictionary];
    [attributes setValue:[NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
    [attributes setValue:leftAlignmentStyle forKey:NSParagraphStyleAttributeName];

    [text setAttributes:attributes range:NSMakeRange(0, [text length])];
}
于 2012-07-13T11:57:06.217 に答える