【发布时间】:2015-07-15 04:12:11
【问题描述】:
我是新来的,但是当我需要一些东西时,我会阅读这个网站,但是今天,我找不到我的问题的答案。
我会尽量详细解释我的问题。
我需要在 NSMutableDictionary 的特定键处添加一个数组。添加到其中的键正确,但我的字典值保持为空。这是我的代码:
dictionarySection = [[NSMutableDictionary alloc] initWithObjects:arraySectionValues forKeys:arraySectionKeys];
dictionaryClip = [[NSMutableDictionary alloc] initWithCapacity:[arraySectionKeys count]];
NSArray *tabSection = [dictionarySection allKeys];
id key,value;
for (int j=0; j<tabSection.count; j++)
{
array = [NSMutableArray array];
key = [tabSection objectAtIndex: j];
value = [dictionarySection objectForKey: key];
//NSLog (@"Key: %@ for value: %@", key, value);
for (SMXMLElement *clip in [books childrenNamed:@"clip"]) {
if([[clip valueWithPath:@"categorie"] isEqualToString:value]){
[array addObject:[clip valueWithPath:@"titre"]];
}
}
NSLog(@"Test array %@",array);
[dictionaryClip setObject:array forKey:key];
[array removeAllObjects];
NSLog(@"Test dictionary %@",dictionaryClip);
}
这里是 NSLog 结果:
2015-07-15 14:34:48.272 test[15533:390301] Test array (
"CDS : ITV Philippe Dunoyer",
"FLASH INFO NCI : crise des banques",
"Les Roussettes sont-elles dangereuses ?",
"Flash infos banques gr\U00e8ve",
"CDS : ITV Paul Langevin",
"CDS : ITV Valls",
"CDS : ITV Victor Tutugoro",
"CDS : ITV Roch Wamytan",
"NCGLAN 20",
"Flash Info : dispositif anti-d\U00e9linquance"
)
2015-07-15 14:34:48.273 test[15533:390301] key : 0
2015-07-15 14:34:48.273 test[15533:390301] Test dictionary {
0 = (
);
}
如我们所见,数组已填满,字典的键是正确的,但数组不在我的字典中。
我应该如何用这个数组填充我的字典?
非常感谢大家的回答:)
Ps : 请原谅我的英语:(
【问题讨论】:
标签: ios objective-c arrays dictionary nsmutabledictionary