Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling specific cells on an NSTableView

I have a tableview with 4 columns. The fist one has some text and the other 3 are checkboxes.
I need to disable 2 of the 3 checkboxes in one particular row. I keep the row number on an NSInteger variable.

I've implemented:

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex 

Where I check the columns identifier to know whether I am at the right column, once I know that I check if the row is correct and set the cell to disable. Code follows:

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex 
{    
    if(([[aTableColumn identifier] isEqualToString:@"column1"]) || ([[aTableColumn identifier] isEqualToString:@"column2"]))
    {   
        if (rowIndex == myindex)    // myindex holds the row index where I need to disable the cells 
        {
            [aCell setEnabled:NO];
        }
    }  
    else
    {
        return;
    }
}

What happens is strange. Colum1 and Colum2 for my specific row are disabled until I click another row, then all the rows get these two columns disabled.

How do I disable these two very specific cells (only in myindex row and only column1 and column2)?

this is a Mac OS X app, not an iOS app.
Thanks

like image 256
Mr Aleph Avatar asked Sep 30 '11 17:09

Mr Aleph


1 Answers

You have to explicitly set the enabled property each time for both cases.

//...
else 
{
   [aCell setEnabled:YES];
}
like image 61
Mundi Avatar answered Nov 11 '22 17:11

Mundi