I have a NSTableView with an NSTableColumn with an NSButtonCell (a checkbox) inside it, which generates a new instance of NSButtonCell each time a row is added, which I configured in IB. However, I'm curious why in the following chunk of code the second NSLog returns 0.
NSLog(@"%ld", (long)[[self.tableView preparedCellAtColumn:0 row:0]state]);
[[self.tableView preparedCellAtColumn:0 row:0]setState:1];
NSLog(@"%ld", (long)[[self.tableView preparedCellAtColumn:0 row:0]state]);
The fact that it returns 0 means that I am sending a message to an instance of NSButtonCell, right? So why doesn't setState: change the return value of the second NSLog?
If it was receiving nil
it would also print 0
, I would suggest trying this
NSLog(@"cell:%@", [self.tableView preparedCellAtColumn:0 row:0])
to ensure you are actually getting a valid cell object from the table view.
Where are you calling that code from? After the table is already being displayed? During initialisation?
If the former then there should be a cell available, if the latter then it may not have been created or reallocated from the pool yet.
Try the NSLog
command above to ensure you are actually getting a cell back and not nil
from the table view.