4

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?""

0

1 Answer 1

13

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)

Sign up to request clarification or add additional context in comments.

2 Comments

Change to self.present(alert, animated: false, completion: nil) solving this problem too.
presentViewController gave me the same error, only self.present worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.