2012-08-23 24 views
1

我有一個NSArrayController,我試圖修改所選對象的值。我使用修改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. 

我是相當新的可可和Objective-C,所以我怕我會在這裏錯過一些相當明顯的東西

+0

你的字典是不可變的,所以你不能改變它(這就是<__ NSDictionaryI 0x10065e6c0>的意思)。 – rdelmar

+0

@rdelmar就是這樣,你會介意把它作爲答案,以便我可以接受它嗎?非常感謝您的支持! – penguinrob

回答

3

你的字典裏是不變的(多數民衆贊成在 「我」 < __NSDictionaryI 0x10065e6c0>的意思),所以這就是爲什麼你會得到錯誤當你嘗試改變它的消息。

2

試試這個:

[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]); 
+0

現在我得到了一個不同的錯誤 - ' - [__ NSDictionaryI insertObject:atIndex:]:無法識別的選擇器發送到實例0x100584860'。這意味着什麼? – penguinrob

+0

與第一條評論相同的錯誤。我不確定您的密鑰是什麼意思 - 密鑰中已經有一個字符串,並且是一個有效的密鑰。 – penguinrob

+0

@penguinrob看看更新的答案。並嘗試第一行:'[ideasListController insertObject:[NSDictionary dictionaryWithObject:@「test」forKey:@「title」] atArrangedObjectIndex:0];'。 –

相關問題