gpt4 book ai didi

ios - UITableView 仅在向下滚动时加载项目

转载 作者:行者123 更新时间:2023-11-29 12:47:38 24 4
gpt4 key购买 nike

当我打开 TableView 时,它会调用下面的函数,但会为 Cell 返回 null。但是当我向下滚动时,它会调用该函数,并返回正确的值。提前致谢

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Formal";
UITableViewCell *cellt = [self.gridtable dequeueReusableCellWithIdentifier:CellIdentifier];

if(labelArray.count==0)
indexPath=0;
else
cellt.textLabel.text= [labelArray objectAtIndex:indexPath.row];//CellIdentifier;//[labelArray objectAtIndex:2];


if (cellt == nil) {
cellt = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cellt;
}

最佳答案

对于其中一个,您应该在设置 textLabel 之前执行 if (cellt == nil)。因为现在您正在设置文本,然后初始化单元格,然后删除文本,因为您的单元格首先不存在。

这就是一个合适的 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"Formal";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

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

return cell;
}

关于ios - UITableView 仅在向下滚动时加载项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23253793/

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