我想添加"确定"按钮以外的其他按钮,它应该只是关闭警报.我想要另一个按钮来调用某个功能.
var logInErrorAlert: UIAlertView = UIAlertView()
logInErrorAlert.title = "Ooops"
logInErrorAlert.message = "Unable to log in."
logInErrorAlert.addButtonWithTitle("Ok")
Run Code Online (Sandbox Code Playgroud)
如何在此警报中添加另一个按钮,然后允许它在点击后调用一个函数,让我们说我们想要新的按钮来调用:
retry()
Run Code Online (Sandbox Code Playgroud) 我没有弄到我的代码有什么问题.我只是用"确定"按钮显示警报,当用户点击"确定"时,警报就应该开始.但它并没有消失.使用Swift3进行编程.viewDidAppear()这个代码是正确的地方吗?或者我做错了什么?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let alertController = UIAlertController(title: "Wrong Item", message: "Could not find details of an item.", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alertController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
更新:当我将相同的代码放在其他控制器中时,它工作.在原始控制器中,在viewDidLoad()中,我有一个Async如下调用.这是因为这个问题吗?
DispatchQueue.global(qos: .background).async {
self.getDetails(onCompletion: {(json: JSON) in
let dict = self.convertToDictionary(text: json.stringValue)
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents()
//Other UI update operation
}
})
}
Run Code Online (Sandbox Code Playgroud)
我还覆盖viewWillDisappear()和viewWillAppear(),只需设定屏幕的标题.