Swift alert view with OK and Cancel: which button tapped?

前端 未结 6 784
耶瑟儿~
耶瑟儿~ 2021-01-30 01:16

I have an alert view in Xcode written in Swift and I\'d like to determine which button the user selected (it is a confirmation dialog) to do nothing or to execute something.

6条回答
  •  遇见更好的自我
    2021-01-30 02:04

    var refreshAlert = UIAlertController(title: "Log Out", message: "Are You Sure to Log Out ? ", preferredStyle: UIAlertControllerStyle.Alert)
    
    refreshAlert.addAction(UIAlertAction(title: "Confirm", style: .Default, handler: { (action: UIAlertAction!) in
        self.navigationController?.popToRootViewControllerAnimated(true)
    }))
    
    refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) in
    
        refreshAlert .dismissViewControllerAnimated(true, completion: nil)
    
    
    }))
    
    presentViewController(refreshAlert, animated: true, completion: nil)
    

提交回复
热议问题