The following code lies within cellForRowAtIndexPath.
1.) i need to modify this code in a way i could, cancel the download or the block when the viewDissapears. I think, i should first initialize a block in the .h file, and then use it in the cellForRowAtIndexPath, then set it to nil when viewDidDissapear. (I am not sure if this approach is correct). Can someone please help me edit this code ?
note: What should hapen is, when the user is on a particular view, and when the following code is downloading some images, the user decides to move to another view. Then i want to cancel the download in the viewDidDissapear method
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
NSData *image = // I will be downloading an URL here
//this will set the image when loading is finished
dispatch_async(dispatch_get_main_queue(), ^{
// I will be displaying the Downloaded image here
});
});
You should not wait for the view to disappear, and cancel the operation in the
prepareForReusemethod of your table view cell. Otherwise you may see a cell get recycled before the download finishes (e.g. because the user did a fast scroll), and then the finished download would show wrong content before the correct one overwrites it. Other than that, your approach looks workable.