title: Present View Controller when the view is not in the window hierarchy
body: <pre><code>import AVFoundation
  import UIKit
  import AVKit
  
  class Class1: UIViewController {
  
  
  var playerViewController = AVPlayerViewController()
  var playerView = AVPlayer()
  var playerTimer = NSTimer()
  
  
  override func viewDidAppear(animated:Bool) {
      let fileURL = NSURL(fileURLWithPath: "file.mp4")
  
      playerView = AVPlayer(URL: fileURL)
  
      playerViewController.player = playerView
  
      self.presentViewController(playerViewController, animated: true){
          self.playerViewController.player?.play()
          self.playerTimer = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector:Selector("stopAfter4seconds:"), userInfo: nil, repeats: false)
      }
  
  }
  func stopAfter4seconds(timer: NSTimer){
      self.playerViewController.player?.pause()
      self.playerViewController.player = nil
      self.presentingViewController?.dismissViewControllerAnimated(false, completion: nil)
      self.presentViewController(GameViewController1(), animated: false, completion: nil)
  }
  
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My Problem is that when I present the line:</p>
  
  <pre><code>self.presentViewController(GameViewController1(), animated: false, completion: nil)
  </code></pre>
  
  <p>I Get the error "attempt to present GameViewController1... whose view is not in the window hierarchy!"</p>
  
  <p>I made sure to play it in viewDidAppear as to add it to the view hierarchy but it doesn't seem to do so</p>
  
  <p>[Update] Okay i realize now that I'm presenting the avplayerviewcontroller and then trying to play the next view controller after. How exactly do I "Dismiss" the AVplayerviewcontroller as well have my next view in the right window hierarchy???</p>