Dato' Mohammad Nurdin Dato' Mohammad Nurdin - 1 year ago 143
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 Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download