I've a table view to which I add columns dynamically. It must be done this way because I can't predict how many or which columns I will need.
Some columns are checkboxes but I can't click on them when I run my application. The column and checkbox are set to be editable but if I click on the checkbox the check won't get set. Am I missing something?
Update
How I'm (trying) setting the state on the che开发者_开发百科ckbox:
- (void)tableView:(NSTableView *)theTableView
setObjectValue:(id)theObject
forTableColumn:(NSTableColumn *)theColumn
row:(int)rowIndex
{
if (theTableView == resultsTableView) {
if ([[theColumn identifier] isEqualToString:CHCheckBoxColumnIdentifier]) {
NSInteger state = [[theColumn dataCell] state];
if (state == NSOnState) {
[[theColumn dataCell] setState:NSOffState];
} else {
[[theColumn dataCell] setState:NSOnState];
}
/*
NSLog(@"%@", theObject);
NSLog(@"%@", theColumn);
NSLog(@"%i", rowIndex);
*/
}
}
}
Are your columns bound to a controller or are you using the NSTableDataSource protocol? I suspect the latter but you'll need to specify.
Going on my assumption: a click on a checkbox is handled the same way as anything else in the -tableView:setObjectValue:forTableColumn:row:
method. Your object will be the state of the button ...
精彩评论