Checkbox on table column won't register click

此生再无相见时 提交于 2019-12-08 01:36:37

问题


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);
            */
        }
    }
}

回答1:


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



来源:https://stackoverflow.com/questions/2141919/checkbox-on-table-column-wont-register-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!