gpt4 book ai didi

iphone - 基于indexPath.row启动UITableViewCells的问题

转载 作者:行者123 更新时间:2023-12-03 17:37:22 25 4
gpt4 key购买 nike

我有以下方法,应该使用数组中的数据填充 UITableView 的单元格。我想使用数据加载到的行作为索引从数组中获取数据。

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


cellComments=(FullCommentCell *)[tableView dequeueReusableCellWithIdentifier:FullCommentCell_ID];
if(cellComments==nil)
{
[[NSBundle mainBundle]loadNibNamed:@"FullCommentCell" owner:self options:nil];
NSLog([NSString stringWithFormat:@"%i",indexPath.row]);
[cellComments loadFullComments:[latestFMLComments objectAtIndex:indexPath.row]];
}
//cellComments.userInteractionEnabled=NO;
return cellComments;

}

这没有按预期工作。该表最终仅填充数组的前三个元素,然后重复使用这些数据,直到我的表结束。该表应该使用我的数组中的所有数据。知道为什么这没有按预期工作吗?

最佳答案

每次返回单元格时,无论是新的还是重复使用的单元格,您都需要设置正确的单元格数据。当您向下滚动时,表格顶部的单元格将被删除并重新用于表格底部。这就是为什么您会看到前几个数据项重复出现。

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

cellComments = (FullCommentCell *)[tableView dequeueReusableCellWithIdentifier:FullCommentCell_ID];
if (cellComments == nil) {
[[NSBundle mainBundle]loadNibNamed:@"FullCommentCell" owner:self options:nil];

// Do any one-time setup here, like adding subviews
}

// Set cell data for both new and reused cells here

[cellComments loadFullComments:[latestFMLComments objectAtIndex:indexPath.row]];
//cellComments.userInteractionEnabled=NO;

return cellComments;
}

关于iphone - 基于indexPath.row启动UITableViewCells的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/722785/

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