uitableViewcell 中的 UIImage 会减慢滚动表格的速度

发布于 2024-11-16 03:20:54 字数 1585 浏览 3 评论 0原文

您好,我正在尝试在 Table 的 cell.image 中获取 facebook 用户的个人资料图片。但它减慢了表格视图的滚动速度。然后我使用 异步加载图像链接但我很困惑如何在我的表方法中使用它

    - (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;
    }

Hello I am trying to get profile image of facebook user in Table's cell.image. But It slows down Scrolling of Table view.Then I used Asynchronous loading of image link But i am confused how could I use this in my Table's method

    - (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;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

戈亓 2024-11-23 03:20:54

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

Its slows down because you are setting the image every time the cellForRowAtIndexPath: is called. Add the image to the cell's imageView only inside the if (cell == nil) block. Then you will see the improvement in scrolling.

浊酒尽余欢 2024-11-23 03:20:54
    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 中的所有数据,这样您就可以进一步提高性能

    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;

This code is creating the described problem ..... try this approch ... once any image is downloaded save it in any temp folder in document directory(make name of ur image such that you can identify each of them uniquely)....and when you have to configure the cell just take the image form tha temp folder every time the method celForRowAtIndexPath is called .... dont use

   UIImageView *image_view = [[UIImageView alloc];

This make no sence here as you are not using it (you are just using its .image property) .... also if possible collect all you data in viewDidLoad in that way you can further improve the performance

晨光如昨 2024-11-23 03:20:54

您确定是异步图像导致问题吗?评论异步图像部分,看看可能是 FbGraphResponse 部分才是真正的原因。

我发现您每次都为图形响应创建图像,这可能会导致速度减慢。

Are you sure it's the async image causing problems? Comment the async image part, and see maybe it's the FbGraphResponse part the actual cause.

I see that you're creating an image each time for the graph response and this can cause a slow-down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文