1

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
GraphicSound
  • 35
  • 2
  • 4

2 Answers2

0

The problem is you are accessing your textfield but not accessing its textvalue. Try your log statement like this below:-

NSLog(@"Field = %@", cellView.textField.stringValue);
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
0

in Table view select cell and give identifier name (same as you are using in code, for your snipped it will be @"ServiceCell"), your code part is right it will work.

laalto
  • 150,114
  • 66
  • 286
  • 303
PR Singh
  • 653
  • 5
  • 15