读取plist文件. iOS程式设计 [英] Reading plist file. iOS Programming

查看:85
本文介绍了读取plist文件. iOS程式设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,无法弄清楚我在做什么错.如您在下面的代码中看到的,我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆