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

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

    Swift 3.0 Version of Jake's Answer

    // Create the alert controller

    let alertController = UIAlertController(title: "Alert!", message: "There is no items for the current user", 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)
    

提交回复
热议问题