Basicly I’m making an image gallery that downloads from the web.
So – when the user scrolls, a new image downloads.
Keep in mind that the code is very simplyfied, just to show you what I mean
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// If new page then:
[self loadNextPicture];
}
-(void)loadNextPicture
{
NSString *url=@"http://www.example.com/image.png";
NSURL *imageURL = [NSURL URLWithString:url];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *nextImage = [UIImage imageWithData:imageData];
myUIImageView.image=nextImage;
}
My problem is that every time a user scrolls to a new page, the application freezes for about a second while it downloads the image. Is there a way I can download it in the background so that the app won’t freeze while downloading?
Appriciate every thoughts on this matter.
Andreas 🙂
NSObject Class Reference