It seems that the UIView has not methods like "didRemoveFromSuperview
" or "willRemoveFromSuperview
".Then,How to listen to the event when a UIView removed from its superView?I should use KVO? thanks in advance!
This works (tested on iOS8):
-(void) didMoveToWindow {
[super didMoveToWindow]; // (does nothing by default)
if (self.window == nil) {
// YOUR CODE FOR WHEN UIVIEW IS REMOVED
}
}
According to the UIView
docs:
The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes.
The window property may be nil... This occurs when the receiver has just been removed from its superview or when the receiver has just been added to a superview that is not attached to a window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With