views:

2396

answers:

1

Apple says:

removeFromSuperview Unlinks the receiver from its superview and its window, and removes it from the responder chain.

  • (void)removeFromSuperview

Never invoke this method while displaying.

So, when I want to get rid of a view, I was used to just kick it off from it's superview. Why should I never invoke that while it's visible? So I must set it to hidden=YES before I do that?

+8  A: 

The specification specifies "while displaying" not "while it is on display". Thus, you should never call removeFromSuperview in the view's drawRect for example.

removeFromSuperview releases the view and may deallocate it. The parent view when attempting to display the view may not expected it to be deallocated and cause a corrupted access.

notnoop