I would like to open new View after clicking on a button. It works, when I make it by UIButton in Main.storyboard, however, I need to make it in code, because I have to use some if-statements with login/password. I tried to make it like it was suggested in other similar questions, but it doesn't work:
@IBAction func login(_ sender: UIButton) {
performSegue(withIdentifier: "Second", sender: self)}
Id of login-view: First;
Id of the second view: Second
If you want to do this, right click drag (or control drag) from the button to the new view controller. This should make a grey line going from the first controller to the second one. You can then click on the little circle in the middle of the segue in interface builder to give it a name and specify the type.
You can use storyboard Id
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "secondStoryboardId") as! SecondViewController
self.present(nextViewController, animated:true, completion:nil)
Your Segue doesn't look to have an identifier in the screenshot. Can you confirm. Please add an identifier to your segue from first view to second and then alter the below code with the name of segue identifier
performSegue(withIdentifier: "Segueidentifier", sender: self)}
To add identifier on the segue, click on the segue in your storyboard and then on the right hand side in the Attributes Inspector add identifier in the Storyboard Segue section
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