2017-04-22 17 views
1

我将使用UIAlertController,但是当我想提出它,我看到这个错误:使用未解决的标识符“存在”的 - 本方法不起作用了

use of unresolved identifier 'present'

这是我的代码:

func showAllert(title: String, msg: String, vc: UIViewController){ 
    let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert) 
    let action = UIAlertAction(title: "ok", style: .default, handler: nil) 
    alert.addAction(action) 

    present(alert, animated: true, completion: nil) 
} 
+0

它在过去的工作对我来说!但现在它不是:( – Mehrdad

+0

你必须在视图控制器上调用present,这个'showAllert'方法的类不是'UIViewController'类。 – rmaddy

+0

谢谢你,你是对的:)) )@rmaddy – Mehrdad

回答

1

如果要专门使用vc: UIViewController提出警告,你应该调用的方法是这样的:

vc.present(alert, animated: true, completion: nil) 
+0

谢谢它工作得很好:))) – Mehrdad

-1

问题是,您呈现视图控制器名称是VC而不是现在。如果你这样做vc(alert, animated: true, completion: nil) 它会工作。

+0

它与以下工作:vc.present(...)...感谢您的答案 – Mehrdad

相关问题