【问题标题】:UIImage in uitableViewcell slowdowns scrolling tableuitableViewcell 中的 UIImage 减慢滚动表
【发布时间】:2011-09-18 12:03:41
【问题描述】:

您好,我正在尝试在 Table 的 cell.image 中获取 facebook 用户的个人资料图片。但它减慢了表格视图的滚动。然后我使用了Asynchronous loading of image链接但我很困惑我怎么能在我的表格方法中使用它

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

        static NSString *CellIdentifier = @"Cell";

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

        cell.textLabel.font = [ UIFont fontWithName:@"Arial" size:10.0];
        cell.textLabel.numberOfLines = 0;

        cell.textLabel.text = [NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] sender]];

        cell.detailTextLabel.text =[NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] post]];

        NSString *get_string = [NSString stringWithFormat:@"%@/picture",[(Facebook *)[dummyArray objectAtIndex:indexPath.row]senderId]];

        AsynchronousImageView *image = [[AsynchronousImageview alloc]init];
[image loadImagewithUrlString:getString];

        FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:get_string withGetVars:nil];

        UIImageView *image_view = [[UIImageView alloc] initWithImage:fb_graph_response.imageResponse];


        cell.imageView.image = image_view.image;



        [image_view release];


        return cell;
    }

【问题讨论】:

    标签: iphone objective-c ios uitableview uiimageview


    【解决方案1】:

    它变慢了,因为每次调用 cellForRowAtIndexPath: 时您都在设置 image。仅在 if (cell == nil) 块内将图像添加到单元格的 imageView。然后你会看到滚动的改进。

    【讨论】:

    • 并非如此。当他重用单元格时,他需要将图像重置为该索引的正确值。
    • 谢谢。现在工作正常。在这种情况下,我不需要使用此异步图像加载...
    • @Andrei Stanescu,是的。但认为它超出了这个问题的范围。 :-)
    • @Andrei Stanescu 这种方法工作正常..不使用这个 asy,图像加载
    【解决方案2】:
        AsynchronousImageView *image = [[AsynchronousImageview alloc]init];
        [image loadImagewithUrlString:getString];
    
        FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:get_string withGetVars:nil];
    
        UIImageView *image_view = [[UIImageView alloc] initWithImage:fb_graph_response.imageResponse];
    
    
        cell.imageView.image = image_view.image;
    

    此代码正在创建所描述的问题.....尝试此方法...一旦下载任何图像,将其保存在文档目录中的任何临时文件夹中(为您的图像命名,以便您可以唯一地识别它们中的每一个)....当您必须配置单元格时,只需在每次调用 celForRowAtIndexPath 方法时从临时文件夹中获取图像 .... 不要使用

       UIImageView *image_view = [[UIImageView alloc];
    

    这在这里毫无意义,因为您没有使用它(您只是在使用它的.image 属性)....如果可能的话,也可以在viewDidLoad 中收集所有数据,这样您可以进一步提高性能

    【讨论】:

      【解决方案3】:

      您确定是异步映像导致了问题吗?评论异步图像部分,看看它可能是 FbGraphResponse 部分的实际原因。

      我看到您每次都在为图形响应创建图像,这可能会导致速度变慢。

      【讨论】:

      • 没有异步图像不会导致问题..实际上是因为每次创建图像都会减慢表格视图的滚动速度,所以我想使用异步。图像示例。而且我不知道如何使用它,这就是我在这里提出的问题,但它在 simon 的建议下运行良好
      猜你喜欢
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-06
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多