title: UITabBarController rotation problem with popViewControllerAnimated and selectedIndex (iPhone SDK)
body: <p>This is a very important auto rotate issue and easy to reproduce. </p>
  
  <p>My application has a UITabBarController. Each tab is a UINavigationController. Auto rotation is handled with normal calls to shouldAutorotateToInterfaceOrientation and didRotateFromInterfaceOrientation.</p>
  
  <p>The interface rotates normally until I call UIViewController.popViewControllerAnimated and change UITabBarController.selectedIndex. </p>
  
  <p>Steps to reproduce:</p>
  
  <ol>
  <li>Create a demo Tab Bar Application.</li>
  <li>Add the following code to the App Delegate .h file:<pre><code>&#35;import &lt;UIKit/UIKit.h&gt;<br>
  @interface TestRotationAppDelegate : NSObject  {
      UIWindow *window;
      UITabBarController *tabBarController;
  }<br>
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;<br>
  @end<br>
  // Redefine the interface to cach rotation messages
  @interface UITabBarController (TestRotation1AppDelegate)<br>
  @end
  </code></pre>  </li>
  <li>Add the following code to the App Delegate .m file:<pre><code>&#35;import "TestRotationAppDelegate.h"<br>
  @implementation TestRotationAppDelegate
  @synthesize window;
  @synthesize tabBarController;<br>
  -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [window addSubview:tabBarController.view];
      [window makeKeyAndVisible];
      return YES;
  }<br>
  -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      return YES;
  }<br>
  -(void)dealloc {
      [tabBarController release];
      [window release];
      [super dealloc];
  }<br>
  @end<br>
  @implementation UITabBarController (TestRotation1AppDelegate)<br>
  -(void)viewDidLoad {
      [super viewDidLoad];
      // Add a third tab and push a view 
      UIViewController *view1 = [[[UIViewController alloc] init] autorelease];
      view1.title = @"Third";
      UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:view1] autorelease];
      NSMutableArray *array = [[NSMutableArray alloc] init];
      [array addObjectsFromArray:self.viewControllers];
      [array addObject:nav];
      self.viewControllers = array;
      // Push view2 inside the third tab
      UIViewController *view2 = [[[UIViewController alloc] init] autorelease];
      [nav pushViewController:view2 animated:YES];
      // Create a button to pop view2
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
      button.frame = CGRectMake(50, 50, 220, 38);
      [button setTitle:@"Pop this view" forState:UIControlStateNormal];
      [button addTarget:self action:@selector(doAction) forControlEvents:UIControlEventTouchUpInside];
      [view2.view addSubview:button];
  }<br>
  -(void) doAction {
      // ROTATION PROBLEM BEGINS HERE
      // Remove one line of code and the problem doesn't occur.
      [self.selectedViewController popViewControllerAnimated:YES];
      self.selectedIndex = 0;
  }<br>
  -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      return YES;
  }<br>
  @end
  </code></pre></li>
  </ol>
  
  <p>The interface auto rotates normally until you tap the button on tab #3.</p>
  
  <p>Your help will be geatly appreciated!</p>