UIAlertController 转到不同的页面 (Swift)
UIAlertController Segue to Different Page (Swift)
我能够为我的按钮编写一个 UIAlertController,它工作正常,但我不知道如何在我按下 YES 或 OK 按钮后转到不同的页面。目前,“是”或“确定”按钮无处可去。
@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)
}
}
您可以在故事板中创建一个 segue,控制从场景顶部的黄色视图控制器拖动到新的视图控制器。然后在检查器中给那个 segue 一个标识符。您可以从代码中的处理程序中调用它。
alert.addAction(UIAlertAction(title:"OK", style: .Default, handler: { action in self.performSegueWithIdentifier("mySegueIdentifier", sender: self) }
解决方案 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)
其中 backToSignIn
是转场名称。
我能够为我的按钮编写一个 UIAlertController,它工作正常,但我不知道如何在我按下 YES 或 OK 按钮后转到不同的页面。目前,“是”或“确定”按钮无处可去。
@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)
}
}
您可以在故事板中创建一个 segue,控制从场景顶部的黄色视图控制器拖动到新的视图控制器。然后在检查器中给那个 segue 一个标识符。您可以从代码中的处理程序中调用它。
alert.addAction(UIAlertAction(title:"OK", style: .Default, handler: { action in self.performSegueWithIdentifier("mySegueIdentifier", sender: self) }
解决方案 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)
其中 backToSignIn
是转场名称。