iOS使用来自Plist的数据填充UITableView [英] iOS Populating UITableView with Data from Plist

查看:76
本文介绍了iOS使用来自Plist的数据填充UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用我的Data.plist文件的内容填充UTTableView. 我需要将此加载到NSMutableArray中. 这是我走了多远:

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:

(查看未加载):

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

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

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

当然在CellForRowAtIndexPath:

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

我在我的Data.plist文件(图片)中写了这个:

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

现在,当我运行该应用程序时.我的TableView仍然是空的.

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

感谢您的时间和帮助!

推荐答案

当前,您的plist的根目录设置为Dictionary.首先将其更改为array.

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"];

这篇关于iOS使用来自Plist的数据填充UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆