views:

323

answers:

2

I am switching between two views by toggling hidden attributes. How would I know when one view gets hidden and/or visible?

Tried setting break points into viewDidLoad, viewDidUnload, viewWillAppear, viewWillDisappear, viewDidDisappear, becomeFirstResponder and resignFirstResponder. Nothing. None of those are called, when I set hidden = YES/NO.

if (self.aController)
    self.aController.view.hidden = YES;
if (self.bController)
    self.bController.view.hidden = NO;
[self.bController viewWillAppear:YES];

I call viewWillAppear by myself, since that view is... subview of subview of view under UITabBarItem. Apple docs told that the setup is unnatural and some automatic notifications have to be done manually. Is this the same problem with not getting becomeFirstResponder and resignFirstResponder which are supposed to be related to hidden status?

+1  A: 

One option is to use Key-Value Observation to observe the hidden property of either views. When the change is triggered, you'll get a message about the change.

Giao
Have to check that, thanx!
JOM
Just to update: good idea, but I couldn't use it because switching from one tab to another doesn't change hidden property. I could change it myself, but calling viewWillAppear/viewWillDisappear was easier choice. Thanx anyway, have to recall Key-Value Observation!
JOM
A: 

Guess Apple docs were right - or at least offered one way to solve the problem. Since I don't get automatic notifications in subViews, but I do get them in mainView, I just "forward" the notifications by myself:

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

// called at tab switch
if (self.aController)
    [self.aController viewWillAppear:YES];
if (self.bController)
    [self.bController viewWillAppear:YES];
}

- (void) viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

// called at tab switch
if (self.aController)
    [self.aController viewWillDisappear:YES];
if (self.bController)
    [self.bController viewWillDisappear:YES];
}

Not sure, if this is the "right" way, but it works. Next problem, please!

JOM