我有一个在线 plist(格式为http://example.com/people.plist)。我怎么能让 UITable 视图从 plist 而不是静态数组中提取名称?
<plist version="1.0">
<array>
<dict>
<key>fname</key>
<string>Scott</string>
<key>sname</key>
<string>Sherwood</string>
<key>age</key>
<string>30</string>
</dict>
<dict>
<key>fname</key>
<string>Janet</string>
<key>sname</key>
<string>Smith</string>
<key>age</key>
<string>26</string>
</dict>
<dict>
<key>fname</key>
<string>John</string>
<key>sname</key>
<string>Blogs</string>
<key>age</key>
<string>20</string>
</dict>
</array>
</plist>
这是我的viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
Person *p1 = [[Person alloc] initWithFname:@"Scott" sname:@"Sherwood" age:30];
Person *p2 = [[Person alloc] initWithFname:@"Janet" sname:@"Smith" age:26];
Person *p3 = [[Person alloc] initWithFname:@"John" sname:@"Blogs" age:20];
self.people = [NSArray arrayWithObjects:p1,p2,p3, nil];
}
这是我的tableView cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
Person *p1 = [self.people objectAtIndex:indexPath.row];
cell.textLabel.text = p1.fname;
return cell;
}