Iphone NSMutableDictionary使用键在Plist中设置数据
我有以下代码Iphone NSMutableDictionary使用键在Plist中设置数据,iphone,plist,nsmutabledictionary,Iphone,Plist,Nsmutabledictionary,我有以下代码 for (int j= 0; j<data.count; j++){ NSString *thedata = [data objectAtIndex:j]; NSMutableDictionary * booksList = [NSMutableDictionary dictionary]; if(j==0){ [booksList setValue:[NSString stringWithFor
for (int j= 0; j<data.count; j++){
NSString *thedata = [data objectAtIndex:j];
NSMutableDictionary * booksList = [NSMutableDictionary dictionary];
if(j==0){
[booksList setValue:[NSString stringWithFormat:@"%@",thedata] forKey:@"name"];
}
if(j==1){
[booksList setValue:[NSString stringWithFormat:@"%@",thedata] forKey:@"author"];
}
[plistDict setObject:booksList forKey:@"Categories"];
[plistDict writeToFile:pListPath atomically: YES];
}
那么谁能帮上什么忙呢?您正在为循环的每个迭代重新创建一个空白字典。移动
NSMutableDictionary * booksList = [NSMutableDictionary dictionary];
在for语句开始之前。如果我理解正确,将write和setobject移动到循环结束后 谢谢。。有时候,一个人为了这么小的事情工作了一整晚之后,需要和他一起看一眼:)再次感谢
NSMutableDictionary * booksList = [NSMutableDictionary dictionary];