UIAlertView已被弃用?

时间:2017-10-29 11:33:10

标签: swift xcode alert deprecated

我想使用带有" Ok"的警告框。按钮返回上一个视图控制器。

我使用此代码:

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

但Xcode表示它已被弃用,所以我试过这个:

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)

但警报框不会显示...... 有什么想法吗?

1 个答案:

答案 0 :(得分:2)

如果您使用swift 3,可以试试这个:

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)

查看here了解更多详情。