I am doing this code
but when i scroll the uitableview image will disappear what i want i want when image once load then it will not disapper.
Please tell me what can i do in this.
__block NSData *image = nil;
dispatch_queue_t imageQueue = dispatch_queue_create("queueForCellImage", NULL);
dispatch_async(imageQueue, ^{
NSString *thumbnailURL = @"http://www.bizfy.com/demo/biscoot/a1.png";
image = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:thumbnailURL]];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = [UIImage imageWithData:image];
[cell setNeedsLayout];
});
});
dispatch_release(imageQueue);
You should store the images in an NSArray, NSDictionary or even in the file system. Instead of only setting
cell.imageView, try to store in a NSMutableArray or save to the disk, and in the next timecellForRowAtIndexPathis called, you access the image where you stored it.Some code with the NSMutableDictionary solution, assuming you are using ARC (try to understand):
In your interface file, you declare a
NSMutableDictionary *dictionaryImages;In your implementation file, initiate it in
viewDidLoadmethod:dictionaryImages = [NSMutableDictionaryImages dictionary];Now, where you download your images, you also should insert the image in your dictionary (I’m not posting all your code, just the relevant parts from that piece)
And then, when
cellForRowAtIndexPathis called, you associate it to the image (of course, if you have access to the thumbnailURL):