bradgonesurfing
bradgonesurfing

Reputation: 32202

Notification when ancestor view is removed from view in iOS

I am specifically interested in a sub UIView getting notification that one of it's ancestor UIViews have been removed from the hierarchy.

I am aware of the callbacks on UIViewController but that doesn't solve the problem of notifying sub UIView's that they have been removed from the hierarchy unless I manually traverse all the subviews and notify them in turn that they are no longer displayed.

Upvotes: 0

Views: 975

Answers (1)

Nekto
Nekto

Reputation: 17877

You can subclass UIView and implement method willRemoveSubview:.

From Apple Docs:

Tells the view that a subview is about to be removed.

- (void)willRemoveSubview:(UIView *)subview

Upvotes: 2

Related Questions