1

我有以下cellForRowAtIndexPath方法代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"champion cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    UIImage *cellIcon = [UIImage imageNamed:[arrayOfChampionPictures objectAtIndex:indexPath.row]];
    [[cell imageView] setImage:cellIcon];

    cell.imageView.frame = CGRectMake(0.0f, 0.0f, 70.0f, 70.0f);

    cell.imageView.layer.cornerRadius = 7;
    [cell.imageView.layer setMasksToBounds:YES];

    cell.textLabel.text = [arrayOfChampionNames objectAtIndex:indexPath.row];

    return cell;
}

包含图片名称arrayOfChampionNames的本地数据库存储在哪里。NSMutableArray我的 UITableView 中有大约 103 个带有图像的单元格。它在第一次滚动时从头到尾滞后,之后平滑滚动。模拟器没有滞后。


我想出了可能的解决方案,但我不知道如何实现它们

  • 滚动后加载图像,
  • 将图像数据预加载到 UITableView 中。
4

2 回答 2

2

我会告诉你滞后来自哪里 - 拐角半径。预先计算图像圆角。动态地执行它们会破坏滚动性能。

于 2012-10-10T00:34:46.163 回答
0

你忘记了一些东西:

static NSString *CellIdentifier = @"champion cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

这样,您将实际利用您创建的可重用标识符。

于 2012-10-09T21:42:33.133 回答