views:

255

answers:

2

I have a class that inherit from UITableViewController, the only orientation allowed is UIInterfaceOreintationPortrait. In this class I'm using the delegate method didSelectRowAtIndexPath: to push another view in which landscape orientation is allowed. The problem is that when I came back from this view in landscape orientation, the TableView is landscape oriented too. I would like too force the TableView to be in portrait mode, how can I do that ?

Thanks for your help.

A: 

As long as your view controller is implementing shouldAutorotateToInterfaceOrientation: to constrain the orientation to portrait, it should "snap back" to portrait mode when you come back.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
David Gelhar
I already implemented this, but it didn't change a thing.
Benj
Hmm... How are you switching between views? For example, are you using a UINavigationController with pushViewController:animated: / popViewControllerAnimated: ?
David Gelhar
I'm using pushViewController:animated:
Benj
In that case, I don't know. Maybe try putting a breakpoint or NSLog in your shouldAutorotateToInterfaceOrientation: method to verify that it's really getting called?
David Gelhar
A: 

If shouldAutorotateToInterfaceOrientation isn't being called, check to see if you have overridden - (id) init.

If you have overridden - (id) init, then you may have forgotten to call super.

Enjoy.

loyalmoses