views:

1250

answers:

5
A: 
  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return YES; } The above method if u using, you will able to call many time if u want with out any error.
RRB
I'm using this method. And it's only being called when the controller loads.
looneygrc
A: 

I think there is no strange behavior here, it is called only one which is right. There is no need to call more than one to decide if the device should rotate to a direction or not.

This method just ask if the device should rotate to a direction or not. If you want to handle the orientation change, you should register for the notification from the UIDeviceDidChangeOrientationNotification and override the following method:

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
    !isShowingLandscapeView)
    {
        [self presentModalViewController:self.landscapeViewController
                            animated:YES];
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait &&
             isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }
}

See more here.

sfa
Thanks for your answer. But i don't understand why in my other controllers shouldAutorotateToInterfaceOrientation is enough to rotate them. And for this specific controller isn't enough. Also in my other controllers everytime I rotate the device shouldAutorotateToInterfaceOrientation is being called.
looneygrc
In other words ...my controller should call shouldAutorotateToInterfaceOrientation everytime i rotate the device to check if the orientation is supported. Well ... my "problematic" controller calls it only when it loads and not when the device rotates.
looneygrc
When the device rotates, it askes the controller if it should support the rotation by querying the "shouldAutorotateToInterfaceOrientation:", if the answer is yes, then it will call the willRotateToInterfaceDuration:duration: to see if it needs to do any other modifications.
sfa
I understand that. But in my case it askes only when controller loads. If i rotate the device it never askes. Nvm ill recreate this controller and see if this will fix it.
looneygrc
as I told you, there are no reason for the iphone os to call this function more than 1 time. So you should look on elsewhere to see what you can do to handle the device orientation.
sfa
Ok.. got that. But why, in my case, it doesn't "auto" rotate?
looneygrc
+1  A: 

I am not sure whether it's the same reason as your case. But I experienced the same thing. the shouldAutorotateToInterfaceOrientation was only called once in the beginning. After some serious debugging by taking code apart, I found that the reason is in my overridden init method. I had this before:

- (id)initWithAlbum:(PhotoAlbum *)theAlbum {
    if (self) {     
        self.photoAlbum = theAlbum;     
    }
    return self;
}

And then I changed to this

- (id)initWithAlbum:(PhotoAlbum *)theAlbum {
    if (self = [super init]) {      
        self.photoAlbum = theAlbum;     
    }
    return self;
}

Note: the only difference is I added [super init] to call the parent init. After this change, the rotation works well and the shouldAutorotateToInterfaceOrientation is being called everytime I rotate the screen. Hope this help.

DaiLak
A: 

Thank you DaiLak! This solved my problem!!!

Glasswing
A: 

See Apple's official Q&A on this issue:

Why won't my UIViewController rotate with the device?

http://developer.apple.com/library/ios/#qa/qa2010/qa1688.html

nybon