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
How might I proceed?
Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.
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)
One way is to just have a modal segue from a button. No IBOutlet required.
Programatically:
@IBAction func scanButton (sender: UIButton!) {
performSegueWithIdentifier("nextView", sender: self)
}
You should add a modal segue and name the identifier. You connect the VC1 to VC2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With