我有一个由 UIImageView 和 UILabel 组成的自定义 UITableViewCell。单元格为 320x104px,imageView 占据了整个区域,标签位于前面。只有8个细胞。
在 ViewDidLoad 中,我预先创建了所有需要的图像,并将它们缓存在正确尺寸的字典中。
当我滚动 UITableView 时,每次遇到新单元格时都会出现明显的滞后。这对我来说毫无意义,因为它使用的图像已经创建和缓存。我对单元格的要求只是让它的 UIImageView 呈现图像。
我在 xib 中使用其视图的自定义单元格并配置我的 UITableView 以使用它:
[self.tableView registerNib:[UINib nibWithNibName:@"ActsCell" bundle:nil] forCellReuseIdentifier:myIdentifier];
单元创建和配置:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* reuseIdentifier = @"ActsCell";
ActsCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
// Configure the cell...
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(ActsCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Act* act = [self.acts objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.title.text = act.name;
cell.imageView.image = [self.imageCache objectForKey:act.uid];
}
什么可能导致滞后?尝试做任何异步操作似乎没有任何好处,因为所有耗时的工作都已完成。