UITableViewController滚动滞后有大量图像

时间:2012-10-09 21:35:37

标签: iphone objective-c ios xcode

我有以下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;
}

arrayOfChampionNamesNSMutableArray中存储的包含图片名称的本地数据库。我的UITableView中有大约103个带有图像的单元格。它首先从头到尾滚动,之后滚动顺畅。模拟器上没有滞后。


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

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

2 个答案:

答案 0 :(得分:2)

我会告诉你滞后的来源 - 角半径。预先计算图像的圆角。动态执行它们会导致滚动性能下降。

答案 1 :(得分:0)

你忘记了什么:

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

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

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