Slow loading the images from URL in UITAbleView.

后端 未结 9 687

I\'m loading the images from URL in UITableView. But it\'s very slow when loading an view. Here\'s an example,

UIImage *image = nil;
image = [UIImage imageW         


        
相关标签:
9条回答
  • 2020-12-20 10:08

    You've to use NSOperationQueue to make your tableview efficient.

    Check this icodeblog tutorial and raywenderlich tutorial

    0 讨论(0)
  • 2020-12-20 10:09

    Have a look at this tutorial. It helped me a lot. When I was using it I was quite new to iOS in general and it was helpful not only with respect to loading images from the web.

    http://www.markj.net/iphone-asynchronous-table-image/

    0 讨论(0)
  • 2020-12-20 10:10

    if you load the image all download from the internet every time , it must be very slow.

    I think you shuold exist your download image to the filePath , and when you will load the image , you can check whether the image has been downloaded before , if not ,then download. if it has been downloaded , you can use imageWithContentsOfFile: method to load the image

    0 讨论(0)
  • 2020-12-20 10:13

    //Make use of dispatch queue for faster processing of data. add this in viewDidLoad

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        NSData * data=[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
        [self performSelectorOnMainThread:@selector(setImage:) withObject:data waitUntilDone:YES];
    });
    

    //once data is got set the image and reload tableview

    -(void)setImage:(NSData *)responseData
    {
    image = [UIImage imageWithData:responseData];
    [tableView reloadData];
    }
    
    0 讨论(0)
  • 2020-12-20 10:14

    With AFNetworking it is more easy.

    //AFNetworking

    #import "UIImageView+AFNetworking.h"
    
    [cell.iboImageView setImageWithURL:[NSURL URLWithString:server.imagen] placeholderImage:[UIImage imageNamed:@"qhacer_logo.png"]];
    
    0 讨论(0)
  • 2020-12-20 10:19

    There are some open source libraries available for this:

    1. HJCache
    2. SDWebImage

    These libraries download image in a asynchronous manner and cache it for further use.

    0 讨论(0)
提交回复
热议问题