2016-07-19 41 views
1

我想使显示了信息的提示对话框,这是我在ViewController.swift代码:无法调用非函数类型“UIViewController?”的值

func showErrorAlert(title: String , msg: String){ 
    let alert = UIAlertController(title: title, message: msg, preferredStyle: .Alert) 
    let action = UIAlertAction(title: "OK", style: .Default, handler: nil) 
    alert.addAction(action) 
    presentedViewController(alert, animated: true, completion: nil) 
} 

最后一行是给我的错误:

"Cannot call value of non-function type "UIViewController?""

回答

10

编辑: 对于斯威夫特3,更改为

present(alert, animated: false, completion: nil) 

您调用了错误的函数。

应该

presentViewController(alert, animated: true, completion: nil) 

而不是presentedViewController(alert, animated: true, completion: nil)

+3

更改为self.present(警报,动画:假的,完成:无)也解决了这个问题。 – eyal

+0

'presentViewController'给了我同样的错误,只有'self.present'工作 – Antek

相关问题