Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 修改NSArrayController对象的值会导致错误_Cocoa_Nsarraycontroller_Key Value Coding - Fatal编程技术网

Cocoa 修改NSArrayController对象的值会导致错误

Cocoa 修改NSArrayController对象的值会导致错误,cocoa,nsarraycontroller,key-value-coding,Cocoa,Nsarraycontroller,Key Value Coding,我有一个NSArrayController,我正在尝试修改所选对象的值。我正在使用 [[[ideasListController selectedObjects] objectAtIndex:0] setValue:@"test" forKey:@"title"]; 尝试更改标题,但这会导致错误: [<__NSDictionaryI 0x10065e6c0> setValue:forUndefinedKey:]: this class is not key value coding

我有一个NSArrayController,我正在尝试修改所选对象的值。我正在使用

[[[ideasListController selectedObjects] objectAtIndex:0] setValue:@"test" forKey:@"title"];
尝试更改标题,但这会导致错误:

[<__NSDictionaryI 0x10065e6c0> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key title.
[setValue:forUndefinedKey:]:
此类不符合密钥标题的密钥值编码。
我对Cocoa和Objective-C相当陌生,因此我担心我可能遗漏了一些非常明显的东西。

试试这个:

[ideasListController insertObject:[NSDictionary dictionaryWithObject:@"test" forKey:@"title"] atArrangedObjectIndex:0];
更新:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

[dict setObject:[NSString stringWithFormat:@"test"] forKey:@"title"];

[ideasListController insertObject:dict atArrangedObjectIndex:0];

[dict release];

NSLog(@"%@", [[ideasListController selectedObjects] objectAtIndex:0]);
试试这个:

[ideasListController insertObject:[NSDictionary dictionaryWithObject:@"test" forKey:@"title"] atArrangedObjectIndex:0];
更新:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];

[dict setObject:[NSString stringWithFormat:@"test"] forKey:@"title"];

[ideasListController insertObject:dict atArrangedObjectIndex:0];

[dict release];

NSLog(@"%@", [[ideasListController selectedObjects] objectAtIndex:0]);

你的字典是不可变的(这就是“I”的意思),所以当你试图更改它时,你会收到错误消息。

你的字典是不可变的(这就是“I”的意思),所以当你试图更改它时,你会收到错误消息。

现在我得到一个不同的错误-
-[\uu-NSDictionaryI insertObject:atIndex:]:发送到实例0x100584860的选择器无法识别
。这意味着什么?和第一条评论一样的错误。我不确定你所说的“检查键”是什么意思-该键中已经有一个字符串,并且是一个有效键。@请看一下更新后的答案。然后尝试第一行:
[ideasListController插入对象:[NSDictionary Dictionary WithObject:@“test”forKey:@“title”]atArrangedObjectIndex:0]。更新和上一条注释中的行都执行时没有任何错误。现在我得到一个不同的错误-
-[\uu NSDictionaryI insertObject:atIndex:]:未识别的选择器发送到实例0x100584860
。这意味着什么?和第一条评论一样的错误。我不确定你所说的“检查键”是什么意思-该键中已经有一个字符串,并且是一个有效键。@请看一下更新后的答案。然后尝试第一行:
[ideasListController插入对象:[NSDictionary Dictionary WithObject:@“test”forKey:@“title”]atArrangedObjectIndex:0]。更新和上一条注释中的行都会执行,没有任何错误。您的字典是不可变的,因此您不能更改它(这就是它的意思)。@rdelmar就是这样,您介意把它作为一个答案,以便我可以接受它吗?非常感谢你抓住了那个!你的字典是不可变的,所以你不能更改它(这就是它的意思)。@rdelmar就是这样,你介意把它作为一个答案,这样我就可以接受它吗?非常感谢你抓住了那个!