如何在我的 tableView 中显示此信息?

How can I display this information in my tableView?

我正在构建一个需要在 tableView 中显示某些信息的应用程序,从 .plist 文件中获取所述信息。在plist文件中,有一个根文件,是一个数组。每个数组项(都是字典)里面有 4 个项:

我需要让 tableView 只有一个标签,显示 "Name" 字符串中的文本。其他项目稍后会用到。

我该怎么做?如有必要,我很乐意提供更多信息。

提前致谢。

您可以在 tableview 中设置从 plistlabel 的值: 将代码放在

方法:- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Exercise" ofType:@"plist"];
exerciseArray = [NSArray arrayWithContentsOfFile:plistPath];

label.text =[[exerciseArray objectAtIndex:indexPath.row]objectForKey:@"Name"];

首先你需要从 NSBundle 获取你的 plist 文件的路径。然后将元素存储在一个数组中,并使用 indexpath.row 处的数组元素为键 "name" 填充标签。希望这可以帮助。

NSString *path = [[NSBundle mainBundle]pathForResource:@"Menu" ofType:@"plist"];
NSMutableArray *menuArray = [NSMutableArray arrayWithContentsOfFile : path];
nameLabel.text = [[menuArray objectAtIndex:indexPath.row]objectForKey: @"name"];

UITableViewCell 定制 class,并根据您的要求进行设计。然后从 plist 文件中获取数据。在 CellForRowAtIndexPath 方法中将数据分配给 CustomTableViewCell