title: Alert views in portrait, iPad in landscape, and unable to rotate to anything but "other" landscape (180 degrees)
body: <p><strong>Update:</strong> Solved. See fix at bottom.</p>
  
  <p>In my iPad app which supports all orientations, if the app is loaded in landscape, weird things happen:</p>
  
  <ol>
  <li>Alert views appear in portrait, even though the rest is in landscape</li>
  <li>Rotating the iPad from landscape to portrait does not trigger a rotation (nor does it trigger any of the shouldAutorotate style methods).</li>
  <li>Rotating the iPad 180 degrees (to "other landscape") does trigger rotation, and after this, the iPad behaves like normal (i.e. rotates correctly to portrait and landscape when rotated). </li>
  </ol>
  
  <p>Alert view screen below. Weird, weird. Any ideas why this might be happening? It only happens when loading in landscape -- loading in portrait and then rotating to landscape works just fine.
  <img src="https://i.stack.imgur.com/ThbU5.jpg" alt="Landtrait!"></p>
  
  <p><strong>Solution:</strong> This problem occurred because I was adding a UIViewController (modally) on top of the main view controller as soon as the app finished loading (more specifically, in the app's <code>viewDidAppear:</code> method). </p>
  
  <p>iOS sends a number of (4) <code>shouldAutorotateToInterfaceOrientation:</code> calls to the current/main view controller after things have started up, to figure out which orientations are currently supported. When I added the other VC so soon, this occurred in the middle of the aforementioned calls. Thus, I only got one or two calls (for "portrait", because it starts with portrait). </p>
  
  <p>The main view controller was then left with a default support of "NO" for the landscape orientations, but the newly added view controller (which is also asked about orientations) now happily responds yes.</p>
  
  <p>If I had removed the other VC (which is in landscape), I would have realized that my main view controller was stuck in portrait. So I had a portrait view, on top of which there was a landscape view. The alerts and such heeded the orientation of the former, hence the disastrous results above.</p>
  
  <p>Additionally, if I tried to rotate to portrait, I couldn't, because the main view controller was already in portrait. Rotating to landscape was also impossible because the other view controller is already in landscape. Only when I did the "landscape but that other one" rotation, did both view controllers agree that rotation was required, and thus the device rotated.</p>
  
  <p>The fix in my case was to simply put the creation of the other controller at a slight delay. using <code>performSelector:withObject:afterDelay.</code> -- 0 seemed to work but I just put it at 1 to be sure. It looks a bit weird, with the main vc appearing and then the other vc, but it's better than the above.</p>