So I've been thinking about this for a few days, and I can't seem to find a good way to make it work.
I have an NSOperationQueue
that allows only ONE operation at a time.
I understand from the documentation :
In OS X v10.6 and later, canceling an operation causes the operation to ignore any dependencies it may have. This behavior makes it possible for the queue to execute the operation’s start method as soon as possible. The start method, in turn, moves the operation to the finished state so that it can be removed from the queue.
That when I send cancel it'll set isCancelled
to YES, but my problem is :
Say I have 20 NSOperation
in the queue and I just cancelled the 18th it'll stay in the NSOperationQueue
until it can run and says it's finished (my NSOperation
checks correctly for isCancelled
) but as it stays in the queue it also stays in the UITableView
which I set dataSource
to something like myOperationQueue.operations
.
And that's what bothers me, user will click Cancel
which will invoke the cancel
method on the NSOperation
but the operation will still be displayed as it's still in the queue.
I thought about invoking start
in the cancel
method but it isn't allowed only the queue can start
it.
EDIT : I also tried to override isFinished
in the cancel
:
[self willChangeValueForKey:@"isFinished"];
_isFinished = YES;
[self didChangeValueForKey:@"isFinished"];
It works but it also send start
to the next NSOperation
in the queue and it can lead to having 2 NSOperation
at the same time and I only want one.