Question

Hi All I have an NSTableView which has three columns. The first one is a checkbox and the third one is a button. The button 'is enabled' state depends on whether or not the checkbox is checked.

I am setting the table content in the awakeFromNib method and I am implementing the checkbox state in the - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row method. I need to find a way setEnabled: for the NSButton

Thanks

No correct solution

OTHER TIPS

A good way to set button states in an NSTableView is to use an NSArrayController and bind it to the columns of the NSTableView:

  • Bind the column that contains the buttons to the NSArrayController (see this example)
  • Under Enabled
    • Set the Controller Key to arrangedObjects
    • Set the Model Key Path to the NSArrayController's button state. For example, let's call it enabled .

Now in the class where you have the NSArrayController and the NSTableView delegate, do something like this after you click a checkbox:

- (void)updateArrayControllerWithButtonState: (BOOL)isEnabled
{
    // theTable is the NSTableView instance variable
    NSInteger row = [theTable clickedRow];

    // Get the array of values that populates the table
    NSMutableDictionary *arrayValues = [[theArrayController arrangedObjects] objectAtIndex:row];

    // Actually change the NSArrayController's value to match
    [arrayValues setObject:[NSNumber numberWithBool:[model isEnabled]] forKey:@"enabled"];

    [theTable reloadData];
}

Provided you set up your bindings properly for the NSArrayController & NSTableView, this function should update the current state of the button to match that of the NSArrayController.

This code is untested but should shed some light on the general idea.

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