title: Auto-rotating views and UIDevice interface notifications
body: <p>I have trouble with auto-rotating interfaces in my iPad app. I have a class called <code>Switcher</code> that observes the interface rotation notifications and when it receives one, it switches the view in window, a bit like this:</p>
  
  <pre><code>- (void) orientationChanged: (NSNotification*) notice
  {   
      UIDeviceOrientation newIO = [[UIDevice currentDevice] orientation];
      if (!UIDeviceOrientationIsValidInterfaceOrientation(newIO))
          return;
      UIViewController *newCtrl = /* something based on newIO */; 
      [currentController.view removeFromSuperview]; // remove the old view
      [window addSubview newCtrl.view];
      [self setCurrentController:newCtrl];
  }
  </code></pre>
  
  <p>The problem is that the new view does not auto-rotate. My auto-rotation callback in the controller class looks like this:</p>
  
  <pre><code>- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) io
  {   
      NSString *modes[] = {@"unknown", @"portrait", @"portrait down",
          @"landscape left", @"landscape right"};
      NSLog(@"shouldAutorotateToInterfaceOrientation: %i (%@)", io, modes[io]);
      return YES;
  }
  </code></pre>
  
  <p>But no matter how I rotate the device, I find the following in the log:</p>
  
  <pre><code>shouldAutorotateToInterfaceOrientation: 1 (portrait)
  shouldAutorotateToInterfaceOrientation: 1 (portrait)
  </code></pre>
  
  <p>…and the <code>willRotateToInterfaceOrientation:duration:</code> does not get called at all. Now what? The orientation changing is becoming my least favourite part of the iPhone SDK… (I can’t check the code on the device yet, could it be a bug in the simulator?)</p>
  
  <hr>
  
  <p>PS. The subscription code looks like this:</p>
  
  <pre><code>[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  [[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(orientationChanged:)
      name:UIDeviceOrientationDidChangeNotification
      object:nil];
  </code></pre>