读取plist文件. iOS程式设计 [英] Reading plist file. iOS Programming
问题描述
我有这段代码,无法弄清楚我在做什么错.如您在下面的代码中看到的,我的supporting files
文件夹中有一个名为shifts.plist
的plist文件.这是我的plist结构.
I have this code and can't figure out what I'm doing wrong. As you can see in the code below I have a plist file called shifts.plist
which is in my supporting files
folder. Here is my plist structure.
NSString *path = [[NSBundle mainBundle] pathForResource:@"shifts" ofType:@"plist"];
dictionary = [[NSMutableDictionary alloc]initWithContentsOfFile:path];
cell.textLabel.text = [secondTableInfo objectAtIndex:indexPath.row];
NSLog(@"%@",[[dictionary objectForKey:@"name"]objectAtIndex:0]);
我最终想阅读name
条目并用它们填充UITableView
.
我使用NSLog
输出dictionary
,我得到了以下内容.所以文件在那里
我错了的解析.
谢谢,
山姆
I would ultimately like to read the name
entries and populate a UITableView
with them.
I used NSLog
to output dictionary
and I got the following. So the file is there it's just
the parsing that I'm getting wrong.
Thanks,
Sam
推荐答案
主要错误:-根是数组,您正在将文件放入字典中.因此请在.h文件中声明NSArray并保留其非原子属性.
Main Error:- root is array and you are taking file into dictionary.So declare a NSArray in .h file and retain,nonatomic its property.
NSString *path = [[NSBundle mainBundle] pathForResource:@"shifts" ofType:@"plist"];
array = [[NSArray alloc]initWithContentsOfFile:path];
NSLog(@"First Index Name %@",[[array objectAtIndex:0] objectForKey:@"Name"]);
我确定它将回答您的问题.
I am sure it will answer your question.
这篇关于读取plist文件. iOS程式设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!