문제

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);
            */
        }
    }
}
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top