I register a NSNotification in viewDidLoad method.
Should I unregister it both in viewDidUnload and dealloc method using the code below?
[[NSNotificationCenter defaultCenter] removeObserver:self];
Thanks.
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.
Yes you should. viewDidUnload is not called when the view controller is deallocated.
Because viewDidLoad is called when the view controller is opened, people sometimes mistakenly assume that its opposite (viewDidUnload) is called when the screen closes. That is not the case, viewDidUnload is only used in low-memory situations.
That’s why we need to unregister for the notifications in dealloc as well.