2016-11-27 15 views

答えて

0

私はNSTextFieldCellをサブクラス化することで回避策を発見し、それはその場エディタとしてNSTextTextViewのサブクラスを返すようにしています。 このサブクラスはNOを返す- drawsBackgroundをオーバーライドする必要があります。 初期化後にこのプロパティを設定するだけでは十分ではないようです。

@interface NonBackgroundDrawingTextView : NSTextView 

@end 


@implementation NonBackgroundDrawingTextView 

- (BOOL)drawsBackground { 
    return NO; 
} 

@end 

@interface CustomTextFieldCell : NSTextFieldCell 

@end 

@implementation CustomTextFieldCell 

- (NSTextView *)fieldEditorForView:(NSView *)controlView { 
    static NSMutableDictionary* FieldEditors = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     FieldEditors = [NSMutableDictionary dictionary]; 
    }); 
    if (FieldEditors[@(controlView.hash)]) { 
     return FieldEditors[@(controlView.hash)]; 
    } 
    NSTextView* textView = [[NonBackgroundDrawingTextView alloc] initWithFrame:NSZeroRect]; 
    [textView setFieldEditor:YES]; 
    [textView setFocusRingType:NSFocusRingTypeExterior]; 
    FieldEditors[@(controlView.hash)] = textView; 
    return textView; 
} 

@end 
関連する問題