When my app gets back to its root view controller, in the viewDidAppear: method I need to remove all subviews.
How can I do this?
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.
Edit: With thanks to cocoafan: This situation is muddled up by the fact that
NSViewandUIViewhandle things differently. ForNSView(desktop Mac development only), you can simply use the following:For
UIView(iOS development only), you can safely usemakeObjectsPerformSelector:because thesubviewsproperty will return a copy of the array of subviews:Thank you to Tommy for pointing out that
makeObjectsPerformSelector:appears to modify thesubviewsarray while it is being enumerated (which it does forNSView, but not forUIView).Please see this SO question for more details.
Note: Using either of these two methods will remove every view that your main view contains and release them, if they are not retained elsewhere. From Apple’s documentation on removeFromSuperview: