【发布时间】:2023-03-15 09:40:01
【问题描述】:
我自定义了自己的 tableview,它包含几个部分,每个部分只包含一行。在 cellForRowAtIndexPath 中,我将 indexPath.section 存储为单元格的属性。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
KEShowcaseTableViewCell *cell = (KEShowcaseTableViewCell*)[tableView dequeueReusableCellWithIdentifier:sectionCellIdentifier forIndexPath:indexPath];
if( cell == nil ){
cell = [[KEShowcaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCellIdentifier];
}
cell.section = indexPath.section;
cell.horizontalTableView.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
但是,在我的 tableview 上上下滚动几次后,我发现 didEndDisplayingCell 中的单元格存储了与参数 indexPath.section 不同的 indexPath.section 值。
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if( cell.section != indexPath.section ){
NSLog(@"something wrong!");
}
}
我会发现我的 tableview 删除了仍在可见区域中的单元格。
我应该在哪里查看这个 tableview?
【问题讨论】:
-
你能把代码贴在
cellforrowatindexpath吗? -
你在哪里设置
cell.section属性?
标签: ios objective-c iphone uitableview