gpt4 book ai didi

uiview - 如何更改 View 单击 UIAlertViewController 中的按钮

转载 作者:行者123 更新时间:2023-11-28 09:18:24 25 4
gpt4 key购买 nike

UIAlertViewController 显示了我所有的文本,但点击后不会切换到另一个 View 。这是代码:

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

最佳答案

这对我有用:

@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 的模态呈现转场,并将标识符命名为 VC2。我从此处的 GitHub UIAlertController 示例改编的这段代码:

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

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

关于uiview - 如何更改 View 单击 UIAlertViewController 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26431385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com