gpt4 book ai didi

swift - 无法向 UIAlertController (Swift) 添加警报操作

转载 作者:行者123 更新时间:2023-11-28 07:03:09 26 4
gpt4 key购买 nike

我正在尝试向 UI 警报添加一个确定按钮,但我无法使用 alertController.addAction 添加它

在这种情况下我该怎么办?

提前致谢!

if error == nil {
let alert: UIAlertController = UIAlertController(title: "Account Created", message: "Please confirm your email", preferredStyle: .Alert)

let okButton = UIAlertAction(title: "Ok", style: .Default) { action -> Void in
self.performSegueWithIdentifier("toMain", sender: self)

alertController.addAction(okButton)


self.presentViewController(alert, animated: true, completion: nil)

}

} else {

println("\(error)")
}

最佳答案

  1. alert 而不是 alertController
  2. alert.addAction 应该在您的 okbutton 操作之外。

更改您的代码:

if error == nil {
let alert: UIAlertController = UIAlertController(title: "Account Created", message: "Please confirm your email", preferredStyle: .Alert)

let okButton = UIAlertAction(title: "Ok", style: .Default) { action -> Void in
self.performSegueWithIdentifier("toMain", sender: self)

}
alert.addAction(okButton)

self.presentViewController(alert, animated: true, completion: nil)
} else {

println("\(error)")
}

关于swift - 无法向 UIAlertController (Swift) 添加警报操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31531060/

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