Reputation: 79
I have noticed an issue under macOS 10.12: When I create a NSTableView with "Sourcelist" Highlight style, the Text-Cells draw a black background while being edited, making the text black on black and actually unreadable.
I wonder if anybody else ran into this issue and if there is a possible workaround.
Upvotes: 1
Views: 157
Reputation: 79
I have found a workaround by subclassing NSTextFieldCell
and make it return a subclass of NSTextTextView
as its field editor.
This subclass needs to override - drawsBackground
returning NO.
Setting this property after initialization does not seem to be enough.
@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
Upvotes: 1