title: Problems with multiple xibs for rotation under iOS6
body: <p>I need to use different xib files for portrait and landscape. I am not using Auto Layout but I am using iOS6. (See <a href="https://stackoverflow.com/questions/17432321/can-ioss-auto-layout-rearrange-ui-widgets">my previous question</a> if you care why.)</p>
  
  <p>I'm following Adam's answer to <a href="https://stackoverflow.com/questions/2496554/easiest-way-to-support-multiple-orientations-how-do-i-load-a-custom-nib-when-th/">this question</a> modified with amergin's initWithNib name trick, modified with my own iPhone/iPad needs. Here's my code:</p>
  
  <pre><code>-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  {    
      [[NSBundle mainBundle] loadNibNamed:[self xibNameForDeviceAndRotation:toInterfaceOrientation]
                                    owner: self
                                  options: nil];
      [self viewDidLoad];
  }
  
  - (NSString *) xibNameForDeviceAndRotation:(UIInterfaceOrientation)toInterfaceOrientation
  {
      NSString *xibName ;
      NSString *deviceName ;
  
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
          deviceName = @"iPad";
      } else {
          deviceName = @"iPhone";
      }
  
      if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) )
      {
          xibName = [NSString stringWithFormat:@"%@-Landscape", NSStringFromClass([self class])];
          if([[NSBundle mainBundle] pathForResource:xibName ofType:@"nib"] != nil) {
              return xibName;
          } else {
              xibName = [NSString stringWithFormat:@"%@_%@-Landscape", NSStringFromClass([self class]), deviceName];
              if([[NSBundle mainBundle] pathForResource:xibName ofType:@"nib"] != nil) {
                  return xibName;
              } else {
                  NSAssert(FALSE, @"Missing xib");
                  return nil;
              }
          }
  
      } else {
          xibName = [NSString stringWithFormat:@"%@", NSStringFromClass([self class])];
          if([[NSBundle mainBundle] pathForResource:xibName ofType:@"nib"] != nil) {
              return xibName;
          } else {
              xibName = [NSString stringWithFormat:@"%@_%@", NSStringFromClass([self class]), deviceName];
              if([[NSBundle mainBundle] pathForResource:xibName ofType:@"nib"] != nil) {
                  return xibName;
              } else {
                  NSAssert(FALSE, @"Missing xib");
                  return nil;
              }
          }
      }
  }
  </code></pre>
  
  <p>and of course I'm doing:</p>
  
  <pre><code>- (BOOL) shouldAutorotate
  {
      return YES;
  }
  
  - (NSUInteger)supportedInterfaceOrientations {
      return UIInterfaceOrientationMaskAll;
  }
  </code></pre>
  
  <p>in my view controller and:</p>
  
  <pre><code>- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
  {
      return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
  }
  </code></pre>
  
  <p>in my delegate.</p>
  
  <p>I have two problems which may be related. First, the easy one. I do not rotate upside down. I have all all the proper bits turned on in xcode for both iPad and iPhone. This may be a separate issue or it may be the core of my problem.</p>
  
  <p>The real problem is that when I rotate to landscape mode my xib is replace but the view is off by 90 degrees.</p>
  
  <p>Here's what my 2 xib's look like. (I've colored them garishly so you can see that they are different.)</p>
  
  <p><img src="https://i.stack.imgur.com/cnPV6.jpg" alt="enter image description here"> and <img src="https://i.stack.imgur.com/GNeMf.jpg" alt="enter image description here"> </p>
  
  <p>and you can see when I run it (initially in Landscape mode) that the landscape xib is correct.</p>
  
  <p><img src="https://i.stack.imgur.com/RTBO0.jpg" alt="enter image description here"></p>
  
  <p>when I rotate to portrait it is also correct</p>
  
  <p><img src="https://i.stack.imgur.com/SgmUW.jpg" alt="enter image description here"></p>
  
  <p>but when I rotate back to landscape the xib is replaced but the view is off by 90 degrees.</p>
  
  <p><img src="https://i.stack.imgur.com/Lk0Yp.jpg" alt="enter image description here"></p>
  
  <p>What's wrong here?</p>