iOS Populating UITableView with Data from Plist

百般思念 提交于 2020-01-07 05:41:07

问题


I am trying to populate a UTTableView with the contents of my Data.plist file. I need to load this into an NSMutableArray. This is how far I came:

(View Did Load):

    NSString *PlistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];

    Array = [[NSMutableArray alloc] initWithContentsOfFile:PlistPath];

    [Array addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Testing 1", @"name", nil]];

And of course at CellForRowAtIndexPath:

cell.textLabel.text = [Array objectAtIndex:indexPath.row];

I wrote this in my Data.plist file (picture):

Now when I run the App. My TableView remains empty.

Thanks for your time and help!


回答1:


Currently your plist's root is set to Dictionary. Change that to array first.

Then use this code to show the data:

cell.textLabel.text = [[Array objectAtIndex:indexPath.row] objectForKey:@"name"];


来源:https://stackoverflow.com/questions/20932578/ios-populating-uitableview-with-data-from-plist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!