NSTableView でボタンの状態を設定する良い方法は、NSArrayController を使用して NSTableView の列にバインドすることです。
- ボタンを含む列を NSArrayController にバインドします (この例を参照してください) 。
- 有効の下
Controller Key
を手配済みオブジェクトに設定します
Model Key Path
を NSArrayController のボタン状態に設定します。たとえば、それをenabledと呼びましょう。
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 の状態と一致させる必要があります。
このコードはテストされていませんが、一般的な考え方に光を当てる必要があります。