Present View Controller在Swift中不起作用

时间:2016-04-20 12:31:28

标签: ios swift

我有以下代码:

   let title = "You are not connected to DropBox"
    let message = "Please go back to the main page and try to log in again"
    let okText = "OK"

    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
    let okayButton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil)
    alert.addAction(okayButton)


    if dbRestClient == nil{
        print("please refresh me")
        presentViewController(alert, animated: true, completion: nil)
    }`

但是我的警报并没有显示出来。我从一个实际显示在页面上的View Controller调用此警报,因此不是我的VC在场景后面工作的情况。请告诉我这里我做错了什么。

1 个答案:

答案 0 :(得分:1)

使用 self.presentViewController(alert,animated:true,completion:nil)

添加self后应该可以工作。