UIView rotation - willRotateToInterfaceOrientation not called

I am trying to autorotate a view and I have the same problem described here: willRotateToInterfaceOrientation will not be called .

Despite the fact that I implemented shouldAutorotateToInterfaceOrientation and returned YES, in each subclass of UIViewController I implemented; willRotateToInterfaceOrientation not called.

Perhaps someone can tell me what I am missing. I have the following View Controllers structure (hopefully this is clear enough ..):

 NavigationController (Programatically) -with root > TabBarController (Programatically) -with tab item > NavigationController (Programatically) -with root > UITableViewController (a Subclass) -pushed to navigator controller > UIViewController (a Subclass). 

Hope someone can help me. Thanks in advance!

+4
source share
2 answers

You can try inserting your controller (NavigationController) into the window using rootviewcontroller.

if not working for you, use UIApplicationWillChangeStatusBarOrientationNotification notifications

Edit

Works:

 // custom controller TestController *t = [[TestController alloc] init]; // navigaton UINavigationController *controllerinsertIntoTab = [[UINavigationController alloc] initWithRootViewController:t]; // tab bar UITabBarController *tabbarController = [[UITabBarController alloc] init]; [tabbarController addChildViewController:controllerinsertIntoTab]; // first navigation UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:tabbarController]; [self.window setRootViewController:controller]; 

specially for you https://github.com/sakrist/TestControllers

Hope this is helpful

+1
source

If you do not receive callbacks on willAutoRotateToInterfaceOrientation in any view controller, add the view controller as the child view controller of the root view controller.

For Eg; let's say self.viewController is your root view controller, and childViewController is a view controller in which you want to receive automatic rotation callbacks, add the following line of code;

[self.viewController addChildViewController:childViewController];

In fact, adding a child view as a controller to any view controller that receives callbacks will also work.

Hope this helps.

0
source

All Articles