How to create an alert box in iphone?

后端 未结 10 2169
我寻月下人不归
我寻月下人不归 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:43

    For swift it is very simple.

        //Creating the alert controller
        //It takes the title and the alert message and prefferred style
        let alertController = UIAlertController(title: "Hello  Coders", message: "Visit www.simplifiedios.net to learn xcode", preferredStyle: .Alert)
    
        //then we create a default action for the alert... 
        //It is actually a button and we have given the button text style and handler
        //currently handler is nil as we are not specifying any handler
        let defaultAction = UIAlertAction(title: "Close Alert", style: .Default, handler: nil)
    
        //now we are adding the default action to our alertcontroller
        alertController.addAction(defaultAction)
    
        //and finally presenting our alert using this method
        presentViewController(alertController, animated: true, completion: nil)
    

    Ref: iOS Show Alert Message

提交回复
热议问题