문제

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

올바른 솔루션이 없습니다

다른 팁

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.

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