views:

69

answers:

1

I've created an NSOperation in the queue like so:

ImageLoadingOperation *operation = [[ImageLoadingOperation alloc] initWithImageURL:url target:self action:@selector(didFinishLoadingImageWithResult:)];
[operationQueue addOperation:operation];
[operation release];

And this works fine but if the view gets popped before the operation finishes the App crashes with "EXC_BAD_ACCESS"

I've tried to cancel the the operation Queue by calling cancelAllOperations but as its already in process it doesn't prevent the App from crashing. The docos say that if the operation is running it is up to the operation to detect that it has been canceled and respond appropriately but not too sure how I would implement this?

Any ideas?

+1  A: 

It is a general problem for View calling some network and then callback.

My solution is you can retain the view before you call the operation. And then, when the operation finishes, you release the view.

- (void)longTask {
   [self retain];
}

- (void)longTaskDidFinish {
   // do something if you want
   [self release];
}
vodkhang
So easy and works a charm. Thanks a heap
Rudiger