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

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

    NSArray *textData=[NSArray new];

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

textData 是我的数组名称,recipes 是执行plist后的名称,我的文本数据为空......错误在哪里。

4

2 回答 2

0

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

CFPropertyListRef plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
                                                          (__bridge CFDataRef)propertyListData,
                                                          kCFPropertyListImmutable, NULL);
NSDictionary *settings = (__bridge NSDictionary *)plist;
于 2015-02-04T08:01:10.513 回答
-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/

于 2013-10-28T11:21:13.817 回答