我想插入一個對象到NSDictionary的數組,但無法找出如何。所有示例都顯示瞭如何使用insertObject:atIndex插入NSDictionary的數組,但是這不會在字典鍵下插入對象。插入一個對象到NSDictionary的NSMutablearray
我現在排列如下:
NSArray *aaa = [NSArray arrayWithObjects:@"Disable" ,nil];
NSDictionary *aaaDict = [NSDictionary dictionaryWithObject:aaa forKey:@"Computers"];
NSArray *bbb = [NSArray arrayWithObjects:@"Enable", nil];
NSDictionary *bbbDict = [NSDictionary dictionaryWithObject:bbb forKey:@"Computers"];
NSArray *ccc = [NSArray arrayWithObjects:@"Enable", nil];
NSDictionary *cccDict = [NSDictionary dictionaryWithObject:ccc forKey:@"Computers"];
[listOfItems addObject:aaaDict];
[listOfItems addObject:bbbDict];
[listOfItems addObject:cccDict];
我想這樣做,但有一個關鍵的「計算機」:
NSArray *ar = [NSArray arrayWithObjects:@"xxxx", @"yyyy", @"zzzz", nil];
NSDictionary *arDict = [NSDictionary dictionaryWithObject:ar forKey:@"Computers"];
[listOfItems insertObject:ar atIndex:1];
再次 - 它確實增加了新的數組,但不在關鍵的「電腦」下。我在這裏錯過了什麼?
謝謝!
你是什麼意思?什麼不工作? 'listOfItems',大概是'NSArray',沒有任何鍵的概念(它不是字典)。 –