Dato' Mohammad Nurdin Dato' Mohammad Nurdin - 1 month ago 22
iOS Question

Swift - 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

Please give me some advice if you can. Thank you.

Answer

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)
Comments