David
David

Reputation: 14414

Why is UITabBarController returning a "..should support at least one orientation" message?

I subclassed UITabBarController in order to override shouldAutorotateToInterfaceOrientation: so that I can support landscape mode in certain circumstances. When I run this, the tab bar controller gives me the following message when the overridden method returns NO

The view controller <...0x644f50> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation.

Any suggestions on how to get ride of the message other than return YES all the time in shouldAutorotateToInterfaceOrientation?

Upvotes: 3

Views: 2166

Answers (2)

EmilioPelaez
EmilioPelaez

Reputation: 19922

If you return NO, it means that your view controller can't be displayed on any of the 4 orientations.

You should think which orientations you want it to support and use the orientation parameter they give you to accept those orientations.

For example, if I wanted my view controller to support portrait and landscape right, this would be my implementation (This could be reduced to a line, but I'm expanding it for the sake of clarity):

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIDeviceOrientation)orientation{
  if(orientation == UIDeviceOrientationPortrait) return YES;
  if(orientation == UIDeviceOrientationLandscapeRight) return YES;
  return NO;
}

Upvotes: 13

Callum Jones
Callum Jones

Reputation: 595

You can use UIInterfaceOrientationIsLandscape() and UIInterfaceOrientationIsPortrait() to handle which specific orientation you want the UIViewController to support.

Upvotes: 0

Related Questions