In which UIViewController method should I set to nil all the occurrences of the view controller as a delegate? Is it viewDidUnload (too early?), dealloc (too late?) or something else?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To avoid EXC_BAD_ACCESS you should set delegate properties to nil in your dealloc. This guarantees that other objects won’t try to send delegate messages to your object after it’s been dealloced. For example, if your UIViewController has a webView property, for which it is a UIWebViewDelegate, you should do:
You could set the delegate to nil earlier if you want to stop receiving delegate messages for some other reason, but it’s not necessary if you’re just trying to avoid EXC_BAD_ACCESS.