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

后端 未结 8 1781
说谎
说谎 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:40

    Swift 4 Update

            // Create the alert controller
            let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
    
            // Create the actions
            let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
                UIAlertAction in
                NSLog("OK Pressed")
            }
            let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) {
                UIAlertAction in
                NSLog("Cancel Pressed")
            }
    
            // Add the actions
            alertController.addAction(okAction)
            alertController.addAction(cancelAction)
    
            // Present the controller
            self.present(alertController, animated: true, completion: nil)
    

提交回复
热议问题