全部,我有一个UITableView,我在用户输入上添加单元格。我的细胞有轻微的透明度,我最近注意到,当我有更多的细胞而不是适合屏幕时,当我向下滚动并向后移动时,暂时离屏的细胞现在有新的细胞位于它们后面! /强>
这显示在我的应用程序中,并且也在视图层次结构调试器中得到证明。
有趣的是,只有当两个或多个单元格滚出屏幕时才会发生这种情况(请注意,计数会跳过位于底部的单元格7,此时正好在屏幕外。
我认为这与缓存UIScrollView数据以加快加载有关?我该如何阻止它?
添加单元格
NSArray *indexPaths = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:numberOfCounters inSection:0], nil];
[counterTable insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
numberOfCounters++;
[counters addObject:[[CKCounter alloc] init]];
cellForRowAtIndexPath:方法
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"CKCounter";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
CKCounter *counter = [counters objectAtIndex:indexPath.row];
[counter setCurrentCount:indexPath.row];
[counter setIndex:indexPath.row];
[cell.contentView addSubview:[counter view]];
[cell.contentView setAutoresizesSubviews:TRUE];
[cell setBackgroundColor:[UIColor clearColor]];
/** Sets up the bounds for the subcounters **/
CGRect frame = cell.contentView.bounds;
frame.size.height -= counterMargins; // This will give the counters an inset
frame.size.width -= counterMargins; // The gap will be split to each side
frame.origin = cell.contentView.bounds.origin;
counter.view.frame = frame;
counter.view.opaque = false;
counter.view.center = cell.contentView.center;
//[NSString stringWithFormat:@"%lu", (unsigned long)[indexPath indexAtPosition:0]]
return cell;
}
另请参阅:This Question