Search code examples
objective-ccocoacheckboxnsoutlineview

Cannot set initial state for checkboxes in NSOutlineView


I have outline view each element of which is checkbox. I want to set initial states for these checkboxes as provided by some business-logic. I am trying to do it in appropriate (I hope) method of NSOutlineViewDelegate:

- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
    NSButton *res = [outlineView makeViewWithIdentifier:@"checkbox" owner:self];
    res.title = [item description];
    if([item intValue] & 1)
        res.state = NSOnState;
    else
        res.state = NSOffState;
    return res;
}

Everything is almost fine, button title changes right. But state changing is completely ignored.


Solution

  • Finally I found the solution. I still do not know WHY this happens, what is difference between assigning checkbox title and assigning checkbox state in this case. But it appears that somebody calls integerValue method of item to set state of checkbox after assigning in my method. So, to solve this problem, I need to ensure that integerValue method of item returns appropriate value.