Iphone 优化tableView滚动

Iphone 优化tableView滚动,iphone,uitableview,Iphone,Uitableview,我的tableView如果额外填充,将以滞后滚动。多达20个单元格运行良好,但超过20个单元格时,滚动时会开始滞后。请建议一个滚动效果更好的实现。我是这样做的: 我已经定义了一个自定义的UITableViewCell类 该单元有4个标签和一个imageView(每个插座都是一个合成属性): 我在我的视图控制器中放置了一个表格视图,并按如下方式填充它: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtInde

我的
tableView
如果额外填充,将以滞后滚动。多达20个单元格运行良好,但超过20个单元格时,滚动时会开始滞后。请建议一个滚动效果更好的实现。我是这样做的:

我已经定义了一个自定义的
UITableViewCell

该单元有4个标签和一个
imageView
(每个插座都是一个合成属性):

我在我的
视图控制器中放置了一个
表格视图
,并按如下方式填充它:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CustomCell";

    MyCustomCell *cell = (MyCustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil];
        for (id currentObject in topLevelObjects)
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (MyCustomCell *) currentObject;
                break;
            }
    }
    [cell.label_descr setText:@"bla-bla-bla"];
    [cell.label_date setText:@"bla-bla-bla"];
    [cell.label_time setText:@"bla-bla-bla"];
    [cell.label_numeric setText:@"bla-bla-bla"];
    [cell.image_view setImage:[UIImage imageWithContentsOfFile:@"bla-bla-bla"]];

    return cell;
}
正如您所看到的,每个单元格中的文本量非常糟糕,用于
UIImageView
的图像大约是25x25.png文件

我的
tableView
应该可以容纳300多个单元格(别怪我,我有一个“来自地狱的客户”)

请建议一种方法,使
tableView
滚动更平滑,没有(太多)延迟。或者用另一种方式向我的“来自地狱”的客户展示那些“该死的300多个细胞”

提前谢谢

注:如果重复,很抱歉,但找到的解决方案根本没有帮助

编辑:

关于用于imageView的图像:

我仅使用两种不同的图像:

  • “复选标记”-事务已完成
  • 还有一个“待定”交易正在进行中
  • 也许我在tableViewCell xib中定义了2个imageView插座,只是选择了所需的imageView,而不是每次设置所需的图像

    找到了解决方案,感谢大家,特别是iNoob和max

  • 在tableViewCell的xib中,我将“复选标记”设置为imageView的默认图像
  • 当定义单元格的值时,在
    cellforrowatinexpath
    中,仅当需要时,我说:

    如果您应该显示挂起的图像:

       [cell setPending];
    
  • 要将“复选标记”替换为“挂起”图像(tableViewCell类中定义的方法),请执行以下操作:

    l

    在那之后,桌子像一个符咒一样滚动。再次感谢大家。干杯

  • 不要遍历所有子视图:
    cell=[topLevelObjects objectAtIndex:0]
  • 使用gcd在后台加载图像,并将其存储在NSDictionary中以便于访问:
  • 伪代码:

    If caches dict contains an object for the URL you want to load
        Retrieve that image from the dict
        Set it as the image
    Else
        Load the image using dispatch_async()
        Add it to the dict
    

    我发现这意味着通过编程而不是使用nib文件来创建单元格可以快5-10%。我不知道这是不是真的,所以尽管如此,也许值得一试

    用下面的代码替换您的代码,然后试用

    有关以下代码:

    1) 将UITableViewCell的IBOutlet置于控制器中。对于下面的代码,它是
    myCustomTableViewCell

     MyCustomCell *customCell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCustomCell"];
     if(customCell == nil) {
         [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil];
         customCell = myCustomTableViewCell;
      }
    

    希望它能起作用。

    我在使用带有文件内容的图像时遇到了这个问题。在一个应用程序中,我只是复制了捆绑包中的所有图像(大约210个),并在另一个应用程序中使用了
    imageNamed
    ,我必须从URL获取图像,所以我尝试延迟加载,并借助SDWebImage库。谢谢大家的回答,请看我的编辑。谢谢。当为imageView呈现不同的图像时,这听起来非常有效+1,但看看我的编辑也。
     MyCustomCell *customCell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"MyCustomCell"];
     if(customCell == nil) {
         [[NSBundle mainBundle] loadNibNamed:@"MyCustomCell" owner:self options:nil];
         customCell = myCustomTableViewCell;
      }