title: Dismiss UIActionSheet programatically in iOS 8 screws up UIApplication's windows/keyWindow
body: <p><strong>Story:</strong></p>
  
  <p>I need to programatically dismiss a UIActionSheet when the app goes to background, and what I did in iOS 7, is to traversal <code>[UIApplication sharedApplication].windows</code> and find a view which is of type <code>UIActionSheet</code>, then dismiss it. It does not work in iOS 8.</p>
  
  <p><strong>Background:</strong></p>
  
  <p>In iOS 8, <code>UIAlertController</code> should be used to present alert or action sheet, and a bit experiment shows that <code>UIActionSheet</code> is internally implemented using <code>UIAlertController</code>:</p>
  
  <p><code>po [[UIApplication sharedApplication] keyWindow] &lt;_UIAlertControllerShimPresenterWindow:</code></p>
  
  <p><code>po [[[UIApplication sharedApplication] keyWindow] rootViewController] &lt;_UIAlertShimPresentingViewController: 0x7faa0cf049f0&gt;</code></p>
  
  <p><code>po [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentedViewController] &lt;UIAlertController: 0x7faa0c8cb9e0&gt;</code></p>
  
  <p>Which has the correct title, message, etc.</p>
  
  <p><strong>Confusion:</strong></p>
  
  <p>I then added some code to dismiss the controller, and it does dismiss it. However, the app now does not respond to any user interaction, and I found that after dismissing, the <code>keyWindow</code> is still <code>_UIAlertControllerShimPresenterWindow</code>, then I'm confused, shouldn't dismissing a presented controller clean up its window? Or, is it because it's dismissed just when the app goes to background so the window hierarchy is not in a normal state thus things are screwed up?</p>
  
  <p>Can anyone provide some opinions?</p>
  
  <p>Thanks!</p>