表格视图与SDWebImage无法顺利运行

时间:2013-05-25 03:45:43

标签: performance uitableview sdwebimage

为什么我的桌面视图不能顺利运行?我使用SDWebImage来设置网址中的图片。我正在尝试在表格视图的每一行中绘制3张图像。

arrList很小时它可以正常工作,但是当我增加arrList时,它变得越来越慢(当我滚动表视图时看起来有点振动)。

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    CustomCellTable *cell = (CustomCellTable*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray * nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellTable" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    [cell setBackgroundColor:brgColor];
    // item 1
    if ((indexPath.row*3) > arrList.count-1) return cell;
    vod *Item = [arrList objectAtIndex:(indexPath.row*3)];
    [cell.image1 setHidden:NO];
    [cell.image1 setImageWithURL:[NSURL URLWithString:Item.imageURl] placeholderImage:[UIImage imageNamed:@"poster_default.png"]];
    [cell makeRating:[Item.rating floatValue] positionOf:14];
    // item 2
    if ((indexPath.row*3 +1) > arrList.count-1) return cell;
    Item = [arrList objectAtIndex:(indexPath.row*3+1)];
    [cell.image2 setHidden:NO];
    [cell.image2 setImageWithURL:[NSURL URLWithString:Item.imageURl] placeholderImage:[UIImage imageNamed:@"poster_default.png"]];
    [cell makeRating:[Item.rating floatValue] positionOf:118];
    // item 3
    if ((indexPath.row*3 +2) > arrList.count-1) return cell;
    Item = [arrList objectAtIndex:(indexPath.row*3+2)];
    [cell.image3 setHidden:NO];
    [cell.image3 setImageWithURL:[NSURL URLWithString:Item.imageURl] placeholderImage:[UIImage imageNamed:@"poster_default.png"]];
    [cell makeRating:[Item.rating floatValue] positionOf:225];

    return cell;
}

1 个答案:

答案 0 :(得分:0)

查看对图像进行下采样,以便在滚动时不存储/加载大图像版本。

https://github.com/toptierlabs/ImageCacheResize

该库将SDWebImage与UIImage + Resize结合在一起。使用它而不仅仅是SDWebImage可能会有所帮助。具体使用以下方法加载图像:

- (void)setImageWithURL:(NSURL *)url andResize:(CGSize)size withContentMode:(UIViewContentMode)mode;