我尝试使用这个功能把plist文件中的内容到一个数组:iPhone - 解析plist文件到一个数组没有成功
NSString *path = [[NSBundle mainBundle] pathForResource:@"DataFile" ofType:@"plist"];
self.contentData = [NSArray arrayWithContentsOfFile:path];
但self.contentData一直被空... 我不不明白为什么。我使用了与Apple“PageControl”示例项目(See here)中显示的代码相同的代码,并使用了一个结构相同的pList文件(列表中包含2个字符串的字典项目)。
路径充满了:/var/Mobile/Applications/somehexvalues/MyApp.app/DataFile.plist
我怎么会知道是怎么回事了? NSLog(@“%@”,[NSDictionary dictionaryWithContentsOfFile:path]);给出:
"Item 0" = {
imageKey = "hearts.png";
nameKey = Hearts;
};
"Item 1" = {
imageKey = "leef.png";
nameKey = Leef;
};
"Item 2" = {
imageKey = "round.png";
nameKey = Round;
};
我知道你确定plist是一个数组,但只是为了让我开心,请添加'NSLog(@“%@”,[NSDictionary dictionaryWithContentsOfFile:path]);' – 2011-03-19 00:29:34
您是否将此plist包含在您的项目中资源? – hoha 2011-03-19 00:35:40
@fluchtpunkt:当然,plist是在项目中:-) NSLog给...看编辑... – Oliver 2011-03-19 01:29:11