I have a UIView element which I am adding to the main view controller.
Due to the design of my code, it so happens that the removeFromSuperview is called twice in different places of my code.
[myview removeFromSuperview];
That is how my code is, so I want to know if calling the ‘removeFromSuperview’ causes any problem.
Or how do I check if the view is in the superview and only the remove it.
e.g
if (myview in superview)
[myview removeFromSuperview];
else
do nothing
The docs for the
removeFromSuperviewis telling the following:It means that no crash or side effect should happen, and a check you’re asking about is already performed by the implementation of this method.
However, if you need to check if your view is added as subview to some other view, you can use the following code: