如何在IOS属性列表中将plist数据加载到数组中

时间:2013-10-28 11:17:00

标签: ios

NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"]];

NSDictionary *dict = [[NSDictionary alloc] initwithContentOfFile:path];

    NSArray *textData=[NSArray new];

textData = [dict objectForkey:@"TableData"];

text数据是我的数组名称, 食谱是plist名称 执行后我的文本数据是空的... 哪里是错误。

2 个答案:

答案 0 :(得分:0)

问题是您以错误的方式将 .plist 转换为字典。检查dict属性,它应该是零。下面列出了从.plist文件创建NSDictionary的代码:

CFPropertyListRef plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
                                                          (__bridge CFDataRef)propertyListData,
                                                          kCFPropertyListImmutable, NULL);
NSDictionary *settings = (__bridge NSDictionary *)plist;

答案 1 :(得分:-1)

试试这个:

textData = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"]];

无论如何,您可以看一下本教程:

http://ios-blog.co.uk/tutorials/how-to-populate-a-uitableview-from-a-plist-property-list/