Q:

NSOperationQueue doesn't stop when [operation cancelAllOperations] is called

I created this queue in my iOS app, and I'd like to stop it:
In my .h file:
NSOperationQueue *uhm;

In my .m file:
in viewDidLoad: NSOperationQueue *uhm = [[NSOperationQueue alloc] init];
in my method:
[uhm addOperation:[NSBlockOperation blockOperationWithBlock: ^{
        … //Here I do operations that retrive data from my server
        [[NSOperationQueue mainQueue] addOperationWithBlock: ^{
            [self.tableView reloadData];
        }];
    }
    }]];

but when I call [uhm cancelAllOperations] it just set the boolean value isCancelled on YES, but doesn't stop the execution of queue!
Please help me!

A:

Cancelling an operation doesn't actually stop any executing operation.
It just stops new ones from being started.
You have to stop any current operations manually in the operation itself.
For instance, if you have code that collects downloaded data then before you concatenate the data check if the operation is cancelled.
If the operation is cancelled then end the operation.

There are many ways to do this. It depends on what is inside your operation.

