title: How to dismiss the current ViewController and go to another View in Swift
body: <p>I am new to Swift and I want to know how to dismiss the current view controller and go to another view.</p>
  
  <p>My storyboard is like the following: MainMenuView -> GameViewController -> GameOverView. I want to dismiss the GameViewController to go to the GameOverView, not to the MainMenuView.</p>
  
  <p>I use the following code in my MainMenuView:</p>
  
  <pre><code>@IBAction func StartButton(sender: UIButton) {
      let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
      let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("GameViewController") as! GameViewController
      self.presentViewController(nextViewController, animated:true, completion:nil)
      restGame()
  }
  </code></pre>
  
  <p>In the GameViewController, I use this code, but it doesn't dismiss the GameViewController.</p>
  
  <pre><code>let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
  let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("GameOverView") as! GameOverView
  self.presentViewController(nextViewController, animated:true, completion:nil)
  </code></pre>
  
  <p>This is My GameOverView Code :</p>
  
  <pre><code>class GameOverView: UIViewController{
      // save the presenting ViewController
      var presentingViewController :UIViewController! = self.presentViewController
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
      }
  
      @IBAction func ReplayButton(sender: UIButton) {
          restGame()
          didPressClose()
      }
      @IBAction func ReturnMainMenu(sender: UIButton) {
          Data.GameStarted = 1
          self.dismissViewControllerAnimated(false) {
              // go back to MainMenuView as the eyes of the user
              self.presentingViewController.dismissViewControllerAnimated(false, completion: nil);
          }
         /* let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
          let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("MainScene") as! MainScene
          self.presentViewController(nextViewController, animated:true, completion:nil)*/
  
      }
      func restGame(){
          Data.score = 0
          Data.GameHolder = 3
          Data.GameStarted = 1
          Data.PlayerLife = 3.0
          Data.BonusHolder = 30
          Data.BonusTimer = 0
      }
      func didPressClose()
      {
          self.self.dismissViewControllerAnimated(true, completion:nil)
      }
      override func shouldAutorotate() -&gt; Bool {
          return false
      }
  
      deinit{
          print("GameOverView is being deInitialized.");
  
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Release any cached data, images, etc that aren't in use.
      }
  
      override func prefersStatusBarHidden() -&gt; Bool {
          return true
      }
  
  
  }
  </code></pre>
  
  <p>Any suggestions?</p>