2012-10-30 52 views
2

当我添加图像到UITableView,即时通讯注意到他们第一次被添加到单元格时,我得到一个生涩的滚动。UITableView慢速滚动UIImage

我不加载它们在远程,而不是我的代码如下所示:

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

MyObject *object = [self.myObjects objectAtIndex:indexPath.row]; 
cell.imageView.image = [UIImage imageNamed:object.imageName]; 

return cell; 

(没有,如果(细胞==无)线作为即时通讯在视图中注册的小区类别做负载)

这是一个不好的方法吗?如果是这样,我应该如何将主包中的图像添加到我的单元格的imageView中?

+0

你使用任何cornerRadius的imageview? – Kassem

+0

不需要石英或任何类似的东西。 。 。 –

+0

你的图像有多大? – Puran

回答

1
  1. 尽量减少图像

  2. 的大小如果您不能缩小尺寸以任何理由,试试下面的代码(operationQueue是NSOperationQueue实例的伊娃)

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"]; 
        [operationQueue addOperationWithBlock:^{ 
         NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"name" ofType:@"jpg"]; 
         UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath]; 
         [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
          UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
          cell.imageView.image = image; 
         }]; 
        }]; 
        return cell; 
    }