3

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?

FOX 9000
  • 123
  • 1
  • 1
  • 6
poyo fever.
  • 742
  • 1
  • 5
  • 22

1 Answers1

3

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.

Community
  • 1
  • 1
trojanfoe
  • 120,358
  • 21
  • 212
  • 242