xcode - UIAlertController 转到不同的页面(Swift)

标签 xcode swift segue uialertcontroller

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

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

        }

    }

最佳答案

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

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

关于xcode - UIAlertController 转到不同的页面(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28591514/

相关文章:

ios - 无法在 cocoa touch uiview 类和 Storyboard 中的 subview 之间控制拖动 xcode

ios - -[当我使用 UITraitCollection 变体时,UITextView setAttributedText :] stops working,

swift - Segue 将标题重置为原始 SWIFT

ios - 为什么在从另一个页面传递值之前,UILable 不会显示?

objective-c - 智能识别电话号码和文本(包括国际号码)

ios - 如何将 double 四舍五入到小数点后的第三位

swift - 如何从谷歌地点选择器标记获取所选位置的地址

xcode - TableView 与 Xib 文件的协议(protocol) UITableViewDataSource 的冗余一致性

swift - 如何创建一个包含 Objective-C 框架的 Swift Pod?

ios - 从导航后退按钮解除 segue