NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist"]];
NSDictionary *dict = [[NSDictionary alloc] initwithContentOfFile:path];
NSArray *textData=[NSArray new];
textData = [dict objectForkey:@"TableData"];
文本数据是我的数组名称,食谱plist
名称执行后我的文本数据是空的...错误在哪里。
问题是你以错误的方式将.plist转换为字典。检查dict
属性,它应该是零。下面列出了从 .plist 文件创建 NSDictionary 的代码:
CFPropertyListRef plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
(__bridge CFDataRef)propertyListData,
kCFPropertyListImmutable, NULL);
NSDictionary *settings = (__bridge NSDictionary *)plist;
试试这个:
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/