2013-10-07 36 views
0

我已經將NSSwitchCells列綁定到NSArrayController。值ON/OFF正確顯示,但是當我點擊它時,值不會改變。開關盒給出點擊的視覺反饋,但值保持不變(選中或不選中)。NSSwitchCell在點擊後不改變值

enter image description here

我已經嘗試了所有種類的綁定選項。

NSDictionary *bindingOptions = [NSDictionary dictionaryWithObjectsAndKeys: 
               [NSNumber numberWithInteger:1], NSContinuouslyUpdatesValueBindingOption, 
               [NSNumber numberWithInteger:1], NSRaisesForNotApplicableKeysBindingOption, 
               [NSNumber numberWithInteger:1], NSConditionallySetsEditableBindingOption, 
               [NSNumber numberWithInteger:1], NSValidatesImmediatelyBindingOption, 

               nil]; 
       [tableColumn bind:@"value" toObject:currentItemsArrayController withKeyPath:[NSString stringWithFormat:@"arrangedObjects.%@", editedColumnmetadata.columnBindingKeyPath] options:bindingOptions]; 

[(NSButtonCell*)cell setButtonType:NSSwitchButton]; 
       [cell setTitle:@""]; 
       [tableColumn setDataCell:cell]; 

感謝

UPDATE:(結合到細胞?)

//[tableColumn bind:@"value" toObject:currentItemsArrayController withKeyPath:[NSString stringWithFormat:@"arrangedObjects.%@", editedColumnmetadata.columnBindingKeyPath] options:bindingOptions]; 
[cell bind:@"objectValue" toObject:currentItemsArrayController withKeyPath:[NSString stringWithFormat:@"arrangedObjects.%@", editedColumnmetadata.columnBindingKeyPath] options:bindingOptions]; 
+0

您是否已將表格列複選框單元綁定到您的arraycontroller? –

+0

@hussainShabbir我沒有。我應該如何精確地綁定它?我已將代碼添加到我的問題中。如果我取消註釋行表列的按鈕被禁用,我無法與它們交互。第二行,綁定到單元格,不會改變當前行爲中的任何內容。 – aneuryzm

回答

0

你必須遵循下面的步驟,讓我知道,如果你需要一些更多的細節: -

首先,您必須將複選框單元格的列綁定到綁定檢查器中的arraycontroller,如下面的截圖所示。在陣列控制器

enter image description here

第二件事,如果你想更新複選框單元格的值,然後寫這下面的操作方法,因此這個動作方法只能連接複選框單元格的表格列。

-(IBAction)clickChekBoxcell:(id)sender 
{ 
    NSInteger chkCell=[sender integerValue]; 
    NSNumber *num=[NSNumber numberWithInteger:chkCell]; 
    NSMutableDictionary *dict=[NSMutableDictionary dictionary]; 
    for(dict in [arrCont arrangedObjects]) 
    { 
     [dict setObject:num forKey:@"checkYesNo"]; 
    } 
    [arrCont rearrangeObjects]; 
}