Question

The following is inside the delegate's viewForTableColumn method. I am dynamically creating table columns in the datasource based on a selection in a list view.

    NSDictionary* rowData = [[self tableData] objectAtIndex:row];
    NSString* identifier = [tableColumn identifier];

    NSTableCellView* result = [tableView makeViewWithIdentifier:@"myCellView" owner:self];
    if (result == nil) {
        result = [[NSTableCellView alloc] initWithFrame:NSMakeRect(0, 0, 90.0, 10.0)];
        _textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 90.0, 10.0)];
        [result setTextField:_textField];
        [[result textField] setStringValue:[rowData objectForKey:identifier]];
    }
    else {
        [[result textField] setStringValue:[rowData objectForKey:identifier]];
    }
    NSLog(@"result text field: %@", [[result textField] stringValue]);

    return result;

Now in

-(void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView             forRow:(NSInteger)row {
NSLog(@"did add: %ld", row);
NSTableCellView* aView = [rowView viewAtColumn:0];
NSLog(@"%@", [[aView textField]stringValue]);
NSLog(@"%@",[[[rowView viewAtColumn:0 ] textField] stringValue]);
}

the textField is a Zombie. What gives? Thanks for your help.

Was it helpful?

Solution

Had to get a reference (IBOutlet) for the NSTableCellView in the window controller. Thats about it, nothing else. Now I can access that via its identifier in the NSTableView delegate; the reference is retained even after removing all the columns and adding new columns to the tableview.

Now dealing with very abysmal tableview performance on a tables ranging from 300-3000 rows! That's for another day.

OTHER TIPS

The only thing I can think of is that when you do:

_textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 90.0, 10.0)];

you are causing a release of whatever was previoisly in _textField.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top