handle when callback to a dealloced delegate?

Posted by athanhcong on Stack Overflow See other posts from Stack Overflow or by athanhcong
Published on 2010-04-27T09:36:05Z Indexed on 2010/04/27 9:53 UTC
Read the original article Hit count: 297

Filed under:
|
|
|

Hi all, I implemented the delegate-callback pattern between two classes without retaining the delegate. But in some cases, the delegate is dealloced.

(My case is that I have a ViewController is the delegate object, and when the user press back button to pop that ViewController out of the NavigationController stack)

Then the callback method get BAD_EXE:

if (self.delegate != nil && [self.delegate respondsToSelector:selector]) {
    [self.delegate performSelector:selector withObject:self withObject:returnObject];
} 

I know the delegate-callback pattern is implemented in a lot of application. What is your solution for this?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about delegate