UIAlertView first deprecated IOS 9

后端 未结 10 1318
南笙
南笙 2020-11-28 02:29

I have tried several ways to use UIAlertController,instead of UIAlertView. I tried several ways but I cannot make the alert action work. Here is my code that works fine in I

10条回答
  •  悲&欢浪女
    2020-11-28 02:47

    Xcode 8 + Swift

    Assuming self is a UIViewController:

    func displayAlert() {
        let alert = UIAlertController(title: "Test",
                                      message: "I am a modal alert",
                                      preferredStyle: .alert)
        let defaultButton = UIAlertAction(title: "OK",
                                          style: .default) {(_) in
            // your defaultButton action goes here
        }
        
        alert.addAction(defaultButton)
        present(alert, animated: true) { 
            // completion goes here
        }
    }
    

提交回复
热议问题