11

I have an iPhone application that I am currently converting to a universal binary to work with the iPad. I have successfully implemented everything I need in terms of layout so that full landscape functionality is now supported in my app (previously I primarily used portrait mode to display content).

But, I have one strange problem, and it ONLY occurs in landscape mode: when I push a view controller onto the stack, it takes two taps on the back button to return to the previous view controller! The first tap shows a blank view, but with the same name on the left-side back navigation button, the second tap takes the controller back to previous view like it should.

I don't have an iPad to test, so I am relying on the simulator. The problem does not show up on the iPhone and doesn't show up if you rotate back to portrait mode.

My app consists of a tabbarcontroller with navigation controllers loaded for its vc's:

//application delegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
//....
WebHelpViewController *vc8 = [[WebHelpViewController alloc] init];
UINavigationController *nv8 = [[UINavigationController alloc] initWithRootViewController:vc8];

[self.tabBarController setViewControllers:[NSArray arrayWithObjects:nv1,nv2,nv3,nv4,nv5,nv6,nv7,nv8,nil]];

To implement landscape capability, the UITabBarController is overridden to autorotate when required:

//CustomTabBarController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return [[(UINavigationController *)self.selectedViewController topViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

... works fine. I navigate into new views using this method

SomeViewController *vc = [[SomeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc release];

Is this only a simulation error? How do I fix this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David F
  • 133
  • 1
  • 7

1 Answers1

10

It sounds like another ViewController is responding to:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

Check this first.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gnasher
  • 1,513
  • 12
  • 17
  • 1
    Thanks mate, that was the problem. I needed to make sure that all my ViewControllers implemented - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; – David F Apr 22 '10 at 22:18
  • If you're using `CMD+N` to create new `UIViewControllers` in XCode, this method is one of the defaults included as part of the template. – Sneakyness May 14 '10 at 16:45
  • grrr I'm facing exactly the same kind of issue : I'm presenting a navigation controller as modal and then I push some ViewControllers. The navController and all pushed controllers return YES to shouldAutorotateToInterfaceOrientation but in landscape, I need to press "back" two times to get the navigation bar properly updated :/ any idea ? – yonel Aug 24 '10 at 17:08
  • hum, I didn't override this method for the default controller :/ that was causing the issue. – yonel Sep 10 '10 at 13:06