Lio
Lio

Reputation: 4282

Rotating UIView - willRotateToInterfaceOrientation not being called

I'm trying to autorotate a view and I have the same problem explained here: willRotateToInterfaceOrientation not being called.

Even though I implemented shouldAutorotateToInterfaceOrientation and returned YES, in every UIViewController subclass I implemented; willRotateToInterfaceOrientation is not being called.

Perhaps somebody could tell me what I'm missing. I have the following View Controllers structure (I hope 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).

I hope someone can help me. Thanks in advance!

Upvotes: 4

Views: 3306

Answers (2)

Suran
Suran

Reputation: 1227

If you are not receiving callbacks on willAutoRotateToInterfaceOrientation in any view controller, add the view controller as your root view controller's child view controller.

For Eg; say self.viewController is your root view controller and childViewController is the view controller in which you want to get auto-rotation callbacks, add the following line of code;

[self.viewController addChildViewController:childViewController];

Actually, adding as the child view controller to any view controller which gets rotation call backs will work too.

Hope it helps.

Upvotes: 0

Volodymyr B.
Volodymyr B.

Reputation: 3441

You can try insert your controller(NavigationController) to window by rootviewcontroller.

if not works for you, use notifications UIApplicationWillChangeStatusBarOrientationNotification

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];

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

i hope it's helpful

Upvotes: 1

Related Questions