Question

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 checkbox:

- (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);
            */
        }
    }
}
Was it helpful?

Solution

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 ...

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