ViewController not responding to didRotateFromInterfaceOrientation

The controller of my view does not respond to didRotateFromInterfaceOrientation , despite the fact that I added the following to my code:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { [self.popOver dismissPopoverAnimated:NO]; if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) { ... My Custom Code... } } 

Am I doing something wrong here?

+3
source share
3 answers

If you cannot inherit from the UIViewController (which is unsuccessful), you can use this :

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

Then register to start receiving UIDeviceOrientationDidChangeNotification notifications.

+3
source

If your UIViewController is a child in some root view, IB does not add it as a child controller to the default root controller. The easiest way to solve this problem is to change the root controller:

 - (void)viewDidLoad { [super viewDidLoad]; [self addChildViewController:(UIViewController*) self.yourChildController]; } 

That should do the trick. Now your child controller will receive both:

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 

and

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 

messages.

+2
source

I think the real answer here (more precisely, the answer to a related question) is that you need to call

 [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 

in your subclass implementation of the didRotateFromInterfaceOrientation method. For example:

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; // Then your code... } 

This is not mentioned in the Apple documentation, but caused some serious and inexplicable problems for me when they are omitted ...

0
source

All Articles