【问题标题】:How to change View clicking on a butto in UIAlertViewController如何更改视图单击 UIAlertViewController 中的按钮
【发布时间】:2014-10-17 18:39:51
【问题描述】:

UIAlertViewController 显示我的所有文本,但单击时不会切换到另一个视图。代码如下:

    let alertController = UIAlertController(title: "Risposta Esatta", message:"",       preferredStyle: UIAlertControllerStyle.Alert)


    alertController.addAction(UIAlertAction(title: "Avanti", style:UIAlertActionStyle.Default,handler: {(UIAlertAction) in
        let secondViewController:SecondViewController = SecondViewController()
        self.presentViewController(secondViewController, animated: true, completion: nil)
    }))

【问题讨论】:

  • 你能确认这是被解雇了吗?

标签: uiview swift


【解决方案1】:

这对我有用:

@IBAction func choiceBtn(sender: UIButton) {
        let alertController = UIAlertController(title: "Hello!", message: "This is Alert sample.", preferredStyle: .Alert)
        let otherAction = UIAlertAction(title: "OK", style: .Default) {
            action in println("pushed OK!")
        }
        let cancelAction = UIAlertAction(title: "CANCEL", style: .Cancel) {
            action in self.performSegueWithIdentifier("VC2", sender: self)
        }

        alertController.addAction(otherAction)
        alertController.addAction(cancelAction)
        presentViewController(alertController, animated: true, completion: nil)
    }

我创建了一个从 VC1 到 VC2 的模态呈现 segue,并将标识符命名为 VC2。这段代码我改编自这里的 GitHub UIAlertController 示例:

https://github.com/eversense/Swift-UIAlertController-Example

另一个 ViewController 没有 segue,所以我添加了它以向您展示。

【讨论】:

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