views:

761

answers:

2

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 before I call that, I should call setHidden:YES? Would that be enough?

+2  A: 

Wow. I've never seen that note in the docs before and I just got a little scared about some code I've written :)

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

The consensus is that it's a poorly worded sentence and you should not invoke this method while in the process of displaying/drawing something. But if it's currently displayed, then it's ok.

I'd really recommend asking Apple for guidance on this one though.

marcc
lol i just got scared like that too
Daniel
+4  A: 

That warning is there so that you don't call removeFromSuperview from within a drawRect: method. The Cocoa runtime makes extensive use of the view hierarchy during drawing operations, so removing a view from its superview while drawing can really screw things up.

Calling removeFromSuperview at any other time is perfectly fine, and there is no need to hide the view prior to removing it.

e.James
makes sense. Maybe they should have written "while drawing" instead of "while displaying" ;-)
HelloMoon
You're probably right :) I filled out the "document feeback" form for the `NSView` documentation to notify Apple of the confusion. All of Apple's developer docs have feedback links at the very bottom of the page. If you come across something like this, chances are good that other people will also find it confusing, so filling out the feedback form is highly recommended.
e.James
It probably comes from the display/displayLayer: method names.
tc.