UIAlertController Segue for another page (Swift)

I managed to write a UIAlertController for my button, and it works fine, but I donโ€™t know how to go to another page when I press the YES or OK button. At the moment, the YES or OK button is not going anywhere.

@IBAction func SubmitButton(sender: AnyObject) { if a > 28.87 { var alert = UIAlertController(title: "H4 with Guide Pins", message: "Can it be removed?", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "YES", style: UIAlertActionStyle.Default, handler: nil)) alert.addAction(UIAlertAction(title: "NO", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) } else if data2.text == "" { var alert = UIAlertController(title: "Dimension", message: "Missing Data Input.", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) } else { var alert = UIAlertController(title: "H4 with Guide Pins", message: "Enter Swallow Dimension.", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) self.view.endEditing(true) } } 
+6
source share
2 answers

You can create a segue in your storyboard by controlling the drag from the yellow view controller at the top of the scene to the new view controller. Then give this unit an identifier in the inspector. You can call this from a handler in your code.

 alert.addAction(UIAlertAction(title:"OK", style: .Default, handler: { action in self.performSegueWithIdentifier("mySegueIdentifier", sender: self) } 
+12
source

Solution in Swift 3

 let alertController = UIAlertController(title: "Email Verification Required", message: "You will receive an email shortly to verify your account this must be done before you can sign in", preferredStyle: .alert) let backToSignIn = UIAlertAction(title: "OK", style: .cancel, handler: { action in self.performSegue(withIdentifier: "backToSignIn", sender: self)}) alertController.addAction(backToSignIn) self.present(alertController, animated: true, completion: nil) 

Where backToSignIn is the name of the segment.

+1
source

Source: https://habr.com/ru/post/982707/


All Articles