将NSTableView内的复选框设置为"YES"

sha*_*rgy 0 cocoa objective-c nsdictionary nstableview

我有NSTableView一个复选框列和一个NSArrayController.

NSTableView被绑定到NSArrayController以显示其内容.复选框列绑定到imgArrayController.arrangedObjects.check1.程序启动时,数组为空.我以这种方式在循环中使用arrayController添加值:

    [imgArrayController addObject:[NSDictionary dictionaryWithObjectsAndKeys:
        [NSImage imageNamed: [NSString stringWithFormat:@"%@" ,fileName]], @"image", 
        [NSString stringWithFormat:@"%@" ,fileName], @"filename", 
        @"YES", @"check1", 
        nil]];
Run Code Online (Sandbox Code Playgroud)

添加了正确的行数,但是当我尝试将复选框设置为YES时出现错误.这是我得到的错误:

2013-02-03 19:11:46.357 Stockuploader[561:303] Error setting value for key path check1 of object {
} (from bound object <NSTableColumn: 0x100152280>   identifier: check1): [<__NSDictionaryI 0x10010c190> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key check1.
Run Code Online (Sandbox Code Playgroud)

有人可以帮我理解我做错了什么吗?行显示在表格内,但它们都是空的.

ipm*_*mcc 6

尝试使用NSMutableDictionary而不是NSDictionary.也尝试使用[NSNumber numberWithBool: YES]而不是@"YES"(这是一个字符串,而不是一个布尔值).

编辑:

在基于单元格的情况下,NSTableView您需要使用arrangeObjects的Controller Key和Model Key Path of 将(不是单元格本身)绑定到arrayController check1.

在基于视图的情况下,NSTableView您需要使用模型键路径将复选框控件绑定到表格单元格视图objectValue.check1.

  • 如果你刚刚在IB中添加它并且从未改变任何东西它是基于单元格的.在我的回答中添加了一些可能有用的信息. (2认同)