gpt4 book ai didi

iphone - 为什么tableview不显示任何数据?

转载 作者:行者123 更新时间:2023-11-29 11:13:25 27 4
gpt4 key购买 nike

我正在使用自定义表格 View 来显示来自 Data Core 的数据,它应该看起来像这样

enter image description here

但我实际上得到的是这个

enter image description here

这是我的代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [[self.fetchedResultsController sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}


- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Item *item = [self.items objectAtIndex:indexPath.row];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
nameLabel.text = item.name;
UILabel *catLabel = (UILabel *)[cell viewWithTag:101];
catLabel.text = item.category;
UILabel *amountLabel = (UILabel *)[cell viewWithTag:102];
amountLabel.text = item.amount;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"AccountCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

[self configureCell:cell atIndexPath:indexPath];

return cell;

}

最佳答案

您的其他数据源方法正在运行,因为您可以看到存在单元格,但没有填充任何内容。

这一行:

Item *item = [self.items objectAtIndex:indexPath.row];

当您使用获取的结果 Controller 时并不常见。应该是

Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath];

如果您检查调试器,您将看到该项目在您当前的代码中可能为 nil。

如果不是这种情况,那么您的标签在原型(prototype)单元和您的代码之间不匹配。同样,这可以在调试器中检查——标签将为零。

关于iphone - 为什么tableview不显示任何数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10529715/

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