3

I'm facing strange behaviour of my custom view controller subclasses on iOS 5.0. I'm not using standart navigation controllers etc. in my iPad application, but I'm presenting all view controllers myself - this is why I needed to call -viewWillAppear and viewDidAppear methods manually.

Since iOS 5.0, it seems like when adding view controller's view as a subview, these methods are called automatically on view's view controller instance. Which means that these methods are called twice in my case.

Any suggestions? other than creating my own view life-cycle methods and rewriting whole app?

Thanks a lot!

user999445
  • 31
  • 3

2 Answers2

6

Add the following to your UIViewController to disable the automatic calling of those -viewWill... and -viewDid... methods:

-(BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
   return NO;
}

This will force iOS 5.0 to stop calling those methods when adding subviews, and won't break anything with iOS 4.x. I'm using this method as long as I continue to support devices on iOS 4.x. Once I drop support for iOS 4 I will refactor my code to use the new approach of swapping view controllers (as described in the Session 102 video posted by hypercrypt).

chris
  • 16,324
  • 9
  • 37
  • 40
1

Check out Session 102 - Implementing UIViewController Containment from WWDC11.

On iOS 5 you need to use proper view controller containment.

hypercrypt
  • 15,389
  • 6
  • 48
  • 59