【问题标题】:UIAlertController Segue to Different Page (Swift)UIAlertController Segue 到不同的页面 (Swift)
【发布时间】:2015-02-18 18:49:33
【问题描述】:

我能够为我的按钮编写一个 UIAlertController,它工作正常,但我不知道如何在按下“是”或“确定”按钮后转到不同的页面。目前,“是”或“确定”按钮无处可去。

@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)

        }

    }

【问题讨论】:

标签: xcode swift segue uialertcontroller


【解决方案1】:

您可以在情节提要中创建一个转场,控制从场景顶部的黄色视图控制器拖动到新的视图控制器。然后在检查器中给那个 segue 一个标识符。您可以从代码中的处理程序调用它。

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

【讨论】:

  • 我得到了它的segue,但是当你segue到另一个ViewController时如何更改ui图像?
  • 您可以调用 prepareForSegue 并使用 segue.destinationViewController 在您的下一个视图控制器中设置图像属性。
  • 好的..谢谢。我会加入的。
【解决方案2】:

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 是转场名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多