gpt4 book ai didi

ios - 为什么我不能将我的 NSDictionary 数据放入 UITableView

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

我有一个 NSDictionary,它包含多个像这样的词典:

{
complete = 0;
description = Description;
"due_date" = "2014-02-28 16:30:03";
name = Task;
priority = 2;
"task_id" = 1;
"user_id" = 1;
},
{
complete = 0;
description = "";
"due_date" = "0000-00-00 00:00:00";
name = "";
priority = 0;
"task_id" = 2;
"user_id" = 1;
}

我想在我的 UITableView 中显示“名称”的每个实例

我试过这个:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
for (task in tasks) {
cell.textLabel.text = [[task objectAtIndex:indexPath.row] valueForKey:@"name"];
}

return cell;
}

但每次我尝试运行该应用程序时都会崩溃。

我做错了什么?

这是我得到的错误:

Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]

最佳答案

将您的代码更改为如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell.textLabel.text = [[tasks objectAtIndex:indexPath.row] valueForKey:@"name"];

return cell;
}

问题是 task 是一个字典,所以它没有响应 objectAtIndex:

顺便说一句,您还需要创建或出列一个 UITableViewCell 实例,但我只是为您纠正了崩溃问题。

关于ios - 为什么我不能将我的 NSDictionary 数据放入 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22237055/

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