单击后,NSSwitchCell不会更改值

时间:2013-10-07 09:03:57

标签: objective-c macos cocoa

我已将NSSwitchCells列绑定到NSArrayController。正确显示值ON / OFF,但是当我单击它时,值不会改变。开关盒提供点击的视觉反馈,但值保持不变(选中或取消选中)。

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

感谢

更新:(绑定到单元格?)

 //[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];

1 个答案:

答案 0 :(得分:0)

您必须按照以下步骤告诉我您是否需要更多详细信息: -

首先,您需要将复选框单元格的列绑定到绑定检查器中的arraycontroller,如下面的屏幕截图所示。

enter image description here

如果要更新checkbox单元格的值,则在数组控制器中输入第二个内容,然后将此操作方法写入此操作方法,并将此操作方法仅连接到复选框单元格的表列。

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