I have a NSTableView
, its data source and delegate have been set. And I want to customize the cell, so I dragged a view-based cell view from the library. Then I created a class ServiceCell
which inherits from NSTableCellView
in order to fully control my special cell. After that, I control-drag from the nib file to the cell class to create the IBOutlet
properties of the image and text field in the cell.
In the NSTableView's delegate methods, I wrote this:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
// Get a new ViewCell
ServiceCell *cellView = [tableView makeViewWithIdentifier:@"ServiceCell" owner:self];
NSLog(@"Field = %@", cellView.textField); //which turns out to be null!!!
if( [tableColumn.identifier isEqualToString:@"ServiceColumn"] )
{
cellView.serviceImage.image = nil;
cellView.nameLabel.stringValue = @"Hello";
return cellView;
}
return cellView;
}
As you can see, the text field is null! But makeViewWithIdentifier:
has found the cell in Interface Builder and displayed the cell in the app window. I just cannot set it's value, Why?