How to add an action to a UIAlertView button using Swift iOS

后端 未结 8 1780
说谎
说谎 2020-12-12 22:13

I want to add another button other than the \"OK\" button which should just dismiss the alert. I want the other button to call a certain function.

var logInE         


        
8条回答
  •  半阙折子戏
    2020-12-12 22:54

    func showAlertAction(title: String, message: String){
        let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: {(action:UIAlertAction!) in
            print("Action")
        }))
        alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.default, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }
    

提交回复
热议问题