views:

69

answers:

1

I am creating an application which involves so many web-service calls. I am using NSOperation to execute the web-service calls. There are several views in the application and I'm calling the web-service each time the view loads. Since it is navigation, if user decides to go back to the previous view even before the operation gets completed, another operation is getting into the queue and will be waiting for the previous operation to be completed. Is there any way to stop the previous operation from being executed when its view changes? pls help

A: 

Did you try something like this in your view controller:

- (void)viewWillDisappear:(BOOL)animated {
    [myOperation cancel];
    ...
}
Zoran Simic
but i need to remove all the operations in queue. i tried [opQueue cancellAllOperations]; but still crashing. I think the operation currently being executed is not getting cancelled.So i tried to waitUntilAllOperations, but its too taking time..
Nithin
@Nithin: Canceling an operation only stops its functioning if the operation checks the isCancelled keypath and stops what it is doing based on that result. It sounds like your operations are not responding to this, so -waitUntilAllOperationsAreFinished is blocking until they've all fully executed. You might also look at how ASIHTTPRequest handles this: http://allseeing-i.com/ASIHTTPRequest/
Brad Larson