I am about to do a
[vistaX removeFromSuperview];
How do I test to see if vistaX is present on the super view before removing it? Removing a view that isn’t there would lead to a crash on the application…
thanks for any help.
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.
You can guard it with:
Although, I wasn’t aware that removeFromSuperview would fail if there wasn’t a superview. Are you sure that this is the issue and it isn’t maybe related to the fact that removeFromSuperview releases the view?
EDIT:
Based on your comment below, it sounds like vistaX’s retain count is going to 0 the first time around and it’s being freed. If you don’t want this to happen, add a property to your class that retains vistaX (i.e. “@property (retain)”) so you can be sure that it’ll always be around.
EDIT EDIT:
Do you have a handle on the superView or one of its ancestors? If so, I would recommend setting a unique tag on the vistaX view. This can be done programmatically or through IB. Then, use the viewWithTag selector on one of the ancestors to search for the vistaX view by its unique tag.