Reputation: 752
I'm developing an app for iOS and I have a view that contains sub views and I want to call a function when any of its sub views is set to hidden.
Can someone point me to the right direction?
Upvotes: 3
Views: 442
Reputation: 122458
OK, so assuming you implement a method in the superview called subview:(UIView *)view wasHidden:(BOOL)hidden
then you would need to call it after setting viewToHide.hidden
:
viewToHide.hidden = YES;
if ([[viewToHide superview] respondsToSelector:@selector(subview:wasHidden:)]) {
[[viewToHide superview] subview:viewToHide wasHidden:YES];
}
A bit crude but I believe it will work. A better solution might be to get the superview to do the hiding itself, via (custom) methods like:
- (void)hideSubview:(UIView *)subview;
- (void)unhideSubview:(UIView *)subview;
and then it can do what it likes after (un)hiding.
Better still might be to use KVO, as has been flagged as a duplicate.
Upvotes: 3