NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"]];
NSDictionary *dict = [[NSDictionary alloc] initwithContentOfFile:path];
NSArray *textData=[NSArray new];
textData = [dict objectForkey:@"TableData"];
text数据是我的数组名称,
食谱是plist
名称
执行后我的文本数据是空的...
哪里是错误。
答案 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/