2016-07-19 39 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

相關問題