Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

didRotateFromInterfaceOrientation not firing when rotating? [duplicate]

Tags:

ios

rotation

ipad

Possible Duplicate:
ViewController not responding to didRotateFromInterfaceOrientation

I'm having trouble with the didRotateFromInterfaceOrientation method not firing in one of my viewcontroller subclasses.

I have an iPad app w/ UISplitViewController as the main view. On the Detail side, I'm using a "hidden" (no toolbar,navbar) navigation controller for lazy view switching. The ViewController I'm wanting to catch didRotateFromInterfaceOrientation on is two levels deep in the navcontroller hierarchy. (None of this should make a difference, but I'm including this info in case there's some particular case that I don't know about)

I have:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

// This doesn't work. :(
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    NSLog(@"Rotate Go!");
}

The view rotates just fine, but didRotateFromInterfaceOrientation never fires.

Any idea what I'm missing?

like image 555
DOOManiac Avatar asked Apr 25 '11 01:04

DOOManiac


1 Answers

If your UIViewController is a child in some root view then IB does not add it as a child controller to the root controller by default. The easiest way to address this is to modify your root controller:

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

This should do the trick. Now your child controller will be receiving both:

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

and

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

messages.

like image 78
Igor Touzov Avatar answered Sep 21 '22 17:09

Igor Touzov