Unfortunately, you cannot stop the execution of the GCD, but there is another way to fix this error. Since the main issue in this thread is stopping execution, I will post a solution based on what you ask using NSOperation.
1- Create NSOperationQueue
NSOperationQueue *_myQueue; _myQueue = [NSOperationQueue new]; _myQueue.name = @"com.my.queue";
2- Reload the table from your queue. (Will I use the blocks normally?)
[_myQueue addOperationWithBlock:^{
3 Now you can cancel execution using
//maybe you will want to do this on viewDidDisappear [_myQueue cancelAllOperations];
Update:
I noticed that you are delaying a table reload call, but NSOperation does not have a delay mechanism. To solve this problem you can simulate a delay using
[NSThread sleepForTimeInterval:1.5]
before calling [tableView reloadData]; inside addOperationWithBlock: or continue using GCD as you are doing right now and change the tableView link to weak to avoid blocking your tableView object, for example:
__weak __typeof__(tableView) weakTable = tableView; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
Hope this helps ...
source share