Reputation: 2437
My Root View Controller is in portrait mode. I have a button on this Root View Controller and the button action code is shown here:
-(IBAction)VideosView
{
VideosDetailViewController *videoview=[[VideosDetailViewController alloc] initWithNibName:@"VideosDetailViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:videoview animated:YES];
[videoview release];
}
I would like my VideosDetailViewController to be in landscape mode. To solve this problem I've tried many methods but none works for me. This is what I have tried so far:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
But this does not work for me. Any suggestions?
Upvotes: 0
Views: 165
Reputation: 149
You can use this method for your problem. It is for Auto Rotation functionality.
-(NSUInteger) supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
Upvotes: 0
Reputation: 1549
only the root view can set the supported interface orientation in iOS6, in this case your root view is the navigation controller, so the supportedInterfaceOrientations method in your VideosDetailViewController is never even called.
one way around this is to create a category on UINavigationController with the following methods. then your VideosDetailViewController or whatever the current view in the navigation controller will be queried.
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations {
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
Upvotes: 1