读取plist文件。 iOS 编程
我有这段代码,无法弄清楚我做错了什么。正如您在下面的代码中看到的,我有一个名为 shifts.plist
的 plist 文件,它位于我的 supporting files
文件夹中。这是我的 plist 结构。
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]);
我最终想读取名称 条目并用它们填充
UITableView
。
我使用 NSLog 输出字典,得到以下结果。所以文件就在那里 我出错的解析。
谢谢,
山姆
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]);
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您需要先调用
objectAtIndex:
,然后调用objectForKey:
例如:
Looks like you need to call
objectAtIndex:
first, then callobjectForKey:
eg:
主要错误:- root 是数组,并且您正在将文件放入字典中。因此,在 .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.
I am sure it will answer your question.