How to create an alert box in iphone?

后端 未结 10 2181
我寻月下人不归
我寻月下人不归 2020-12-23 21:30

I would like to make an alert type box so that when the user tries to delete something, it says, \"are you sure\" and then has a yes or no for if they are sure. What would b

10条回答
  •  抹茶落季
    2020-12-23 21:54

    Being that UIAlertView is now deprecated, I wanted to provide an answer to future coders that come across this.

    Instead of UIAlertView, I would use UIAlertController like so:

    @IBAction func showAlert(_ sender: Any) {
      let alert = UIAlertController(title: "My Alert", message: "This is my alert", preferredStyle: UIAlertControllerStyle.alert)
    
      alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action) in 
        alert.dismiss(animated: true, completion: nil)
      }))
      self.present(alert,animated:true, completion:nil)
    }
    

提交回复
热议问题