Sachin
Sachin

Reputation: 9

UIAlertController is showing error in latest Xcode

I'm creating a simple alert but it is showing me this error.

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func but (action:UIButton) {

        let alertcontroller = UIAlertController(title: "Title", message: "message", preferredStyle: .Alert)

        let alert = UIAlertAction(title: "Action titel", style: .Default, handler: nil)
        alertcontroller.addAction(alert)
        self.presentedViewController  (alertcontroller, animated:true, completion: nil)

           }

}

it's showing this error **strong text**

Upvotes: 0

Views: 354

Answers (2)

swiftBoy
swiftBoy

Reputation: 35783

this is what, works for me with Swift

@IBAction func but (action:UIButton) 
{
        let alert = UIAlertController(title: "Title", message:"message", preferredStyle: .Alert)
        alert.addAction(UIAlertAction(title: "Okay.", style: .Default) { _ in })

        //Show
        dispatch_async(dispatch_get_main_queue(), ^ {
        self.presentViewController(alert, animated: true){}
       });
}

Upvotes: 0

André Slotta
André Slotta

Reputation: 14030

it has to be presentViewController(...) instead of presentedViewController(...)

Upvotes: 1

Related Questions