What is the correct way to remove a view from it if it is no longer needed?

Apple says:

removeFromSuperview Disconnects the receiver from its supervisor and its window and removes it from the responder chain.

  • (voids) removeFromSuperview

Never call this method while displaying.

So, before I call, I have to call setHidden: YES? Would it be enough?

+2


source to share


2 answers


This warning exists, so you don't call removeFromSuperview

from a method drawRect:

. The Cocoa runtime makes extensive use of the view hierarchy during drawing operations, so removing a view from its supervisor while drawing can really hurt.



Calling removeFromSuperview

at any other time is perfectly fine and there is no need to hide the view until it is deleted.

+3


source


Wow. I have never seen this note in the docs before and I just got a little scared of the code I wrote :)

http://www.iphonedevsdk.com/forum/iphone-sdk-development/9729-curious-thing-removefromsuperview-doc.html



The consensus is that this is a poorly worded proposal and you shouldn't call this method while displaying / drawing something. But if it is currently displayed, then that's okay.

I would recommend contacting Apple for advice on this.

+1


source







All Articles