Async image downloader

前端 未结 5 1187
北海茫月
北海茫月 2021-02-01 11:37

I have write a little class to perform the download of the images by using an NSURLConnection. The idea it\'s to delegate the download to this class to avoid to block the execu

相关标签:
5条回答
  • 2021-02-01 11:58
    NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
        [img_data setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.str_url]]]];
        [pool release];
    
    0 讨论(0)
  • 2021-02-01 12:06

    Simply follow the steps:

        1) Download SDWebImage below  And drag to your xcode project. 
    

    Click here to Download the SDWebImage

       2) Write the following code in your .h file #import "UIImageView+WebCache.h"
       3) Write the following code for your image view 
      [yourImageView setImageWithURL:[NSURL URLWithString:@"www.sample.com/image.png"]];
    

    Thats its... you have done!!!

    0 讨论(0)
  • 2021-02-01 12:07

    Use SDWebImage simply. I'm also using that one. Loading images smoothy. Am using below code to show the image from URL

    [myImageView setImageWithURL:[NSURL URLWithString:@"www.sample.com/image.png"] placeholderImage:[UIImage imageNamed:@"lod.png"] 
    success:^(UIImage *image, BOOL cached)
    {
        productImageDetails.image = image;
    } 
    failure:^(NSError *error) {
        productImageDetails.image =[UIImage imageNamed:@"no_image.jpg"];
    }];
    

    Success part will display the image from webService. And, if there's any image failed to load or anyother failure issue you can load your own image there simply. There are more functionalities with that example. You can just refer it.

    0 讨论(0)
  • 2021-02-01 12:11

    Cesar

    For async image loading, caching and threaded operation, I use SDImageCache class from http://github.com/rs/SDWebImage. I also wrote my own several times, but this one is brilliant and I've thrown all my old code away.

    From its documentation:

    Just #import the UIImageView+WebCache.h header, and call the setImageWithURL:placeholderImage: method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be handled for you, from async downloads to caching management.

    Hilton

    0 讨论(0)
  • 2021-02-01 12:15

    This system works quite good, but i can't get updated the UIImageView inside the cells of a UITableViewCell, any idea ? (actually the cell it's updated when I click on it) There is a better way to implement this functionality ? (actually the need are: non-blocking, caching system

    Have you tried using [tableView reloadData]; Call it at the end of connectionDidFinishLoading method

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