Deidara
Deidara

Reputation: 677

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

I want to make an alert dialog showing up with messages and here's my code in ViewController.swift:

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

The last line is giving me an error:

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

Upvotes: 4

Views: 11350

Answers (1)

Happiehappie
Happiehappie

Reputation: 1074

EDIT: For Swift 3, change it to

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

You called the wrong function.

Should be

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

Instead of presentedViewController(alert, animated: true, completion: nil)

Upvotes: 13

Related Questions