10

In iOS 4.x or lower, viewDidAppear and viewWillAppear, viewDidDisappear and viewWillDisappear, such ViewController's delegate methods are not getting called. The same methods work fine with the iOS 5.x.

Why? Is it a bug in iOS 4.x or lower. Because in iOS 5.x all those methods gets called in proper manner and sequence.

Thanks in advance, Mrunal

Mrunal
  • 13,982
  • 6
  • 52
  • 96
  • Could you explain how you come to his conclusion ? Do you log something from these methods which do show in iOS5 but not in iOS4 ? – teriiehina Jan 12 '12 at 20:34
  • Yes I have used NSLog also and Breakpoints also... Tried also on both simulator as well on device. – Mrunal Jan 13 '12 at 17:55
  • 1
    This depends on you viewController hierarchy that how are you managing your content viewController and Container viewController. – fibnochi Feb 01 '12 at 08:16
  • means? how to manage view hierarchy for that.. – Mrunal Feb 01 '12 at 09:23

2 Answers2

3

For IOS4.x i use the UINavigationController delegate methods like this:

-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [activeView viewDidAppear:YES];
    }
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
        [activeView viewWillAppear:YES];
    }
}

I hope this helps!

user1935005
  • 46
  • 1
  • 2
2

If your view controller is a child of another view controller, (i.e. it's a UINavigationController inside a UIViewController, or vice versa, etc.), the child's viewDidAppear, viewWillAppear, etc. methods will not get called. The solution is to have the parent call into them like:

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

I know this happens through iOS 4.3. In iOS 5 there is a new set of methods specifically for handling these cases: Implementing a Container View Controller

quellish
  • 21,123
  • 4
  • 76
  • 83