Search code examples
iosobjective-cuiimagensdata

Loading takes a while when i set UIImage to a NSData with a url.


NSData *imageUrl = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[self.content objectAtIndex:indexPath.row] valueForKey:@"imageUrl"] ]];
cell.thumbnailImageView.image=[UIImage imageWithData:imageUrl];

this is how i use imageUrl to load them into UIImage but it takes a while to load and the program seems like it crashed or entered to an infinite loop.

How can i make the content of UIImage with url but faster?


Solution

  • use sdwebimage and down load the library file from here

    the few steps you do follow

    add the sdwebimage in your project after that

    in your .h file

    #import "UIImageView+WebCache.h"
    

    in your .m file

    call the single line in your cellforRowAtIndexPath

    [cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:[[self.content objectAtIndex:indexPath.row] valueForKey:@"imageUrl"]]
                                         placeholderImage:[UIImage imageNamed:@"placeholder.png"]];