iOS 5:UITableView单元格不能平滑滚动

NCF*_*USN 2 iphone uitableview ios

使用:

  • iOS 5,ARC,StoryBoards.

每个单元格上都有1个图像和文本.滚动时图像不会调整大小.有两个版本的images image.png和image@2x.png.

通过在故事板中使用UIImageView和UILabel来管理自定义单元格.

码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Continent *continent=[self.items objectAtIndex:[indexPath row]];
ContinentCell *cell = (ContinentCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.continentName.text=continent.continentName;
    cell.textView.text=continent.countriesHash;
    cell.imageView.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
 return cell;
}
Run Code Online (Sandbox Code Playgroud)

邪恶在哪里?先感谢您.

lor*_*ean 12

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
Run Code Online (Sandbox Code Playgroud)

太贵了.您希望在后台异步加载图像,然后在准备好时将其显示在主线程上.

这是一个非常粗略的解决方案

    cell.imageView.image = nil;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      UIImage * img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
      dispatch_sync(dispatch_get_main_queue(), ^{
        cell.imageView.image = img;
      });
    });
Run Code Online (Sandbox Code Playgroud)


inn*_*pps 5

查看抛光您的应用程序:26:48 提高WWDC 2011的响应性和性能视频的提示和技巧.他们已经准确地讨论了你所面临的问题.不要错过,这将是非常有帮助的..!