gpt4 book ai didi

ios - 来自 plist 的 UITableView 加载到字典的 NSArray 中

转载 作者:行者123 更新时间:2023-11-28 19:04:40 25 4
gpt4 key购买 nike

我已经阅读了很多有关此主题的操作方法,但我一直无法弄明白。

如果我有这样的 plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>color</key>
<string>brown</string>
<key>height</key>
<real>40</real>
<key>length</key>
<real>75</real>
<key>level</key>
<real>2</real>
<key>name</key>
<string>bear</string>
<key>note</key>
<string>ugly, but strong</string>
<key>width</key>
<real>30</real>
</dict>
<dict>
<key>color</key>
<string>tan</string>
<key>height</key>
<real>20</real>
<key>length</key>
<real>30</real>
<key>level</key>
<real>4</real>
<key>name</key>
<string>dog</string>
<key>note</key>
<string>cute</string>
<key>width</key>
<real>8</real>
</dict>
<dict>
<key>color</key>
<string>chestnut</string>
<key>height</key>
<real>75</real>
<key>length</key>
<real>90</real>
<key>level</key>
<real>3</real>
<key>name</key>
<string>horse</string>
<key>note</key>
<string>fast</string>
<key>width</key>
<real>22</real>
</dict>
<dict>
<key>color</key>
<string>gray</string>
<key>height</key>
<real>20</real>
<key>length</key>
<real>85</real>
<key>level</key>
<real>2</real>
<key>name</key>
<string>shark</string>
<key>note</key>
<string>hungry!</string>
<key>width</key>
<real>35</real>
</dict>
</array>
</plist>

我可以像这样加载数据并打印整个列表:

NSString *path = [[NSBundle mainBundle]pathForResource:@"testdata" ofType:@"plist"];
NSMutableArray *foodsList = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSLog(@"Did Load - FoodsList = %@", foodsList);

但是当我将它加载到 UITableView 中以便我可以得到一个名称列表时,我无法让它工作。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

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

return cell;
}

NSMutableArray *keyValues = testdata[key];字典和数组类型之间的行失败。

我做错了什么?

谢谢,

最佳答案

您没有在 cellForRowAtIndexPath 内的任何位置设置文本:

设置单元格标签文本

cell.textLabel.text = @"Hello World";

关于ios - 来自 plist 的 UITableView 加载到字典的 NSArray 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21592737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com