问题
The log lines below will show "Table cell: [valid value logged here]" but "Text field: (null)".
I'm actually trying to build an NSOutlineView programmatically, and it works with a cell-based approach, but not with a view-based approach. Can someone tell me what I'm doing wrong?
-(NSView*)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
NSTableCellView* view = [outlineView makeViewWithIdentifier:tableColumn.identifier owner:self];
if (view == nil) {
view = [[NSTableCellView alloc] init];
view.identifier = tableColumn.identifier;
}
view.textField.stringValue = @"TEST";
NSLog(@"Table cell: %@", view);
NSLog(@"Text field: %@", view.textField);
return view;
}
来源:https://stackoverflow.com/questions/27102024/why-does-nstablecellview-alloc-init-produce-a-nil-text-field