Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 Rotation issue with UITabBarController and UINavigation Controller

I have one issue with iOS8.

Here I have structure of my view hierarchy.

Window ==> UITabBarController ==> 2 Tab Tab 1 ==> UINavigationController1 ==> UIViewController1 as root view controller Tab 2 ==> UINavigationController2 ==> UIViewController2 as root view controller

Now everything works perfect with one orientation.

But problem is with this testing steps:

  1. Put log in both ViewController's viewDidLoad method for tracking event
  2. Start app
  3. FirstViewController's viewDidLoad will call. Now stay on this view only.
  4. Rotate to landscape.
  5. This is magic part. SecordViewController's viewDidLoad method get called which is not yet activated by Tab2 then also it is loading with viewDidLoad.

This issue is only on iOS8.
Tested for all devices.

like image 828
Manish Avatar asked Oct 14 '14 07:10

Manish


1 Answers

I had the same problem. I noticed that on iOS8 when the orientation of the device is changing viewWillTransitionToSize:withTransitionCoordinator: is getting called on UITabBarController, and UITabBarController calls viewDidLoad method of any viewcontroller that has not been loaded yet.

For now,in my UITabBarController subclass I override this method to not call [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator].

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    //Do not call [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    NSLog(@"Device orinetation changed");
}
like image 168
alireza Avatar answered Sep 22 '22 00:09

alireza