The following code is within the cellForRowAtIndexPath
. I need to edit this code to the following situations;
1.) If there was a problem to download the image this block should return a setFailedBlock
block, How can i add it to my code ?
2.) While the image is downloading the user changes the view, then i want to stop executing this code (Stop the download). I think i should write the cancel the block in the viewdiddissapear
or viewwilldissapear
methods. But i don't know how to write the code to cancel the download. Can someone show me how to do this ?
(note: this block is inside the cellForRowAtIndexPath
method so have to access it from viewdiddissapear
or viewwilldissapear
)
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
NSData *someimageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:someimageURL]];
dispatch_async(dispatch_get_main_queue(), ^{
[cell.imageviewofsomeimage setImage:[UIImage imageWithData:someimageData ] ];
});
});