R1'
R1'

Reputation: 639

UIAlertView deprecated?

I want to use an alert box with a "Ok" button to return to the previous view controller.

I use this code :

let alert = UIAlertView(title: "",
                            message: "bla",
                            delegate: nil,
                            cancelButtonTitle: "OK")
alert.show()

But Xcode says that it is deprecated, so I've tried this :

let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Button", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

but the Alert Box won't display... Any ideas?

Upvotes: 0

Views: 375

Answers (1)

Kerberos
Kerberos

Reputation: 4166

If you use swift 3 you can try this:

let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Button", style: UIAlertActionStyle.Default, handler: nil))
self.present(alert, animated: true, completion: nil)

Check here for more detail.

Upvotes: 2

Related Questions