Search code examples
iosswiftxcode6

Change view controller using action button


How can I switch the view controller using UIButton? Here is my code:

@IBAction func scanAction(sender: AnyObject) {
      //switch view controller 
}

When I click the Scan button, it will go to a login form.

My view controller in Main.storyboard is like this

enter image description here

How might I proceed?


Solution

  • I already found the answer

    let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
    
    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
    self.presentViewController(nextViewController, animated:true, completion:nil)