简体   繁体   English

目前的View Controller在Swift中不起作用

[英]Present View Controller doesn't work in Swift

I have got the below piece of code : 我有以下代码:

   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)
    }`

However my alert doesn't show up. 但是我的警报没有显示。 I am calling this alert from a View Controller that actually shows on the page so its not the case where my VC is working behind the scene. 我是从实际上显示在页面上的View Controller调用此警报的,因此我的VC在后台运行时不是这种情况。 Please let me know what I am doing wrong here. 请让我知道我在做什么错。

Use self.presentViewController(alert, animated: true, completion: nil) instead. 请改用self.presentViewController(alert,animation:true,complete:nil)

Should work after adding self. 添加自我后应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM