繁体   English   中英

UITableView滚动

[英]UITableView scrolling

我用10行填充表格视图。 当我向上滚动表格时,前两行或第三行被冻结了一段时间。 我只看到最后一行2或3秒。 我意识到滚动表会调用cellForRowAtIndexPath和willDisplayCell函数。 我使用这些功能。 似乎对这些函数的调用减少了响应时间。 如何滚动表格时禁用调用这些函数? 请注意,我不想禁用滚动。

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [[self.items objectAtIndex:indexPath.row] valueForKey:@"name"]; 

if ([indexPath row] % 2) 
    cell.backgroundColor = [UIColor whiteColor];
else 
    cell.backgroundColor = [UIColor colorWithRed:0/255.0 green:46/255.0 blue:59/255.0 alpha:0.1];

return cell;

您不能这样做,这是tableview的正常行为,但是您应该提高这些函数的性能,例如,如果您从远程源加载图像,请考虑使用延迟加载技术

你不能停止调用这些方法。 如果您为他们发布代码,我们可以帮助您优化它们。

UITableViews缓慢的第一个原因是没有重复使用您的单元格。 你在重用你的细胞吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM