大家好,我有一个有三列的NstableView。第一个是复选框,第三个是一个按钮。按钮“已启用”状态取决于是否检查了复选框。

我正在将表内容设置在 awakeFromNib 方法和我正在在 - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row 方法。我需要找到一种方法 setEnabled: 为了 NSButton

谢谢

没有正确的解决方案

其他提示

在NstableView中设置按钮状态的一种好方法是使用NSArrayController并将其绑定到NstableView的列:

  • 将包含按钮包含按钮的列绑定到NsarrayController(请参阅 这个示例)
  • 在下面 已启用
    • 设置 Controller Key布置对象
    • 设置 Model Key Path 到NSARRAYCONTROLLER的按钮状态。例如,让我们称之为 已启用 .

现在,在您拥有NSarrayController和NstableView委托的班级中,单击复选框后进行类似的操作:

- (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];
}

只要您适当地为NSarrayController&nstableView设置绑定,则此功能应更新按钮的当前状态,以匹配NsarrayController的绑定状态。

该代码未经测试,但应该阐明一般想法。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top