I have a view that exits in its own class, with its own xib.

This view is initialized and added as a subview to my viewController view.

When the view is initialized, the method layoutSubviews is called where i customize some stuff in the view.

BUT which method is called when the view is removed from the superview (if any)?

For example, for a ViewController, viewWill/DidDisappear is called. Is there a similar method to a UIView (opposite to the layoutSubviews)?

Thanks in advance

---EDIT---

I just found a method that is called both on adding and removing a subView:

- (void)willMoveToSuperview:(UIView *)newSuperview

AND if newSuperview == 0, you can customize the removing of the subview.

Am i right or is it a tacky way to handle the situation?

有帮助吗?

解决方案

BUT which method is called when the view is removed from the superview (if any)?

-removeFromSuperview is called, so you can override that if you need to do some housekeeping when the view is removed. Just remember to call super's version, too.

-layoutSubviews isn't necessarily only called when the view is added to a superview -- it's called whenever layout is needed. For example, it might be called when the orientation changes, or when the superview lays itself out again, or when the view's frame changes. There's really not an inverse of -layoutSubviews because none is needed. (What would it be called? -messupSubviews? ;-))

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top