1

I have an app where I have a few different views in one app. I use view.hidden = YES/NO; to show these views when I need them to be shown. Is there a viewDidLoad i can use for each specific view as it is shown, or a viewDidAppear.. Or is it assumed that these views, being shown or not are already loaded.

Thanks! Joe

billybob2
  • 681
  • 1
  • 8
  • 17
  • possible duplicate of [IOS, UIView, Detect Hidden State Change in Subview](http://stackoverflow.com/questions/17033581/ios-uiview-detect-hidden-state-change-in-subview) – NRaf Dec 30 '14 at 00:36
  • In addition to my answer, you can use KVO as indicated in the answer NRaf provided, but usually that's overkill. – Aaron Brager Dec 30 '14 at 00:38

2 Answers2

1

Once your view controller's viewDidLoad method is called, self.view - your view controller's main view - has loaded. If you added subviews to it, for example in a storyboard or in loadView, those have been loaded as well.

There is no method that's automatically called when you hide or unhide these views. It's expected that you'd know when this happens since you're the one doing it.

If you want, you could make view controller properties for each view, and then override the setter. Then your setter will get notified when it happens.

Create the property:

@property (nonatomic, assign) BOOL someviewIsHidden;

Override the setter:

- (void) setSomeviewIsHidden:(BOOL)someViewIsHidden {
    _someViewIsHidden = someViewIsHidden; // Set the iVar backing the property
    self.theview.hidden = someViewIsHidden; // Hide (or unhide) the view

    // Do whatever else you want when this property is changed
}
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
0

Your going to need to call a method after you call view.hidden = yes/no to perform the code that you want, there isn't anyway for the view to tell you. On another note it is assumed they are already loaded, because in order for them to be able to be visible you have to initialize them, using initWithFrame: or something similar.