willRotateToInterfaceOrientation not being called

17,688

Solution 1

Is this views viewController a subview of some other root view controller thats not a navigation controller? if so then the call does not propagate to the subviews controller, so that might be why your view isnt rotating.

Solution 2

I have a similar problem and saw Daniel's answer however I can't find any confirmation of this in the developer documentation. Not that I don't believe the answer but I don't really understand why the orientation call does not propagate.

Someone gave me a trick that works using something like this:

[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

Solution 3

One thing to look for is I found if I had UIPopoverController called in [UINavigationController viewDidAppear], then willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation are not called. It looks like UIPopoverController being modal blocks the rotation method calls.

Solution 4

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.

Solution 5

Yes me too. Ok, it won't get called in a sub-viewcontroller - have to pass it down. Can deal with that. And the notification idea works well except that you only get "did..." not "will..." (afaik) and anyway it's a messy solution to a problem which shouldn't be there.

My mistake was to call [super loadView] in my loadView. Not supposed to do that. When I removed [super loadView] and alloc'd the view myself willRotateToInterfaceOrientation started working.

What's really weird is that the [super loadView] was in the sub-viewcontroller and the event wasn't even reaching the top one...

Share:
17,688

Related videos on Youtube

Michael Waterfall
Author by

Michael Waterfall

Updated on September 26, 2020

Comments

  • Michael Waterfall
    Michael Waterfall over 3 years

    I'm returning YES in my view controller's shouldAutorotateToInterfaceOrientation function, and I can see using breakpoints that YES is being returned, however the willRotateToInterfaceOrientation method isn't being called, and nor is any other rotating method. It seems like after returning YES nothing happens!

    Any ideas?

    Mike

  • Michael Waterfall
    Michael Waterfall over 14 years
    I'm trying to handle the calls in a table view controller that is the root of a navigation controller, which itself is a tab in a tab controller. Is that the right place to detect it?
  • Brad Larson
    Brad Larson about 13 years
    Ask the latter part as a new question, because it doesn't belong in an answer. No one will be able to help you here.
  • Deratrius
    Deratrius about 13 years
    I find my question too similar to the OP's to make a new question, the trick works and solved my problem. I was wondering out of curiosity more than necessity. Thanks though.
  • Brad Larson
    Brad Larson about 13 years
    All you need to do is link back to this question and answer in your new question, then ask your additional question. People will be able to read the context of this question in order to answer yours, and I bet you'll get a decent answer from someone. Stack Overflow is not a traditional discussion forum, and questions asked within answers tend to get deleted to keep the site clean.
  • Oscar
    Oscar almost 13 years
    I don't really see any substantive difference between his question and the OP's.