Search code examples
nsoperationnsoperationqueuekill-processdispatch-asyncnetworkonmainthread

How to genuinely cancel operations


I'm using NSOperation to perform two operations. The first operation is loading the data from Internet, while the second operation is updating the UI.

However, if the viewDidDisappear function is triggered by user, how can I stop the data loading process? I tried

[taskQueue cancellAllOperations], 

but this function only marks every operation inside as cancelled while not literally cancel the executing process.

Could anyone please give some suggestions? Thanks in Advance.


Solution

  • Thanks sincerely for your answer. But I find out that actually

    [self performSelectorInBackground:@selector(httpRetrieve) withObject:nil];
    

    solve my problem. The process don't have to be cancelled. And feels like NSOpertaions is not running in the background. Thus, back to super navigation view while the nsoperation is still running, the UI will become stuck!