Reputation: 9
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)
}
}
Upvotes: 0
Views: 354
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
Reputation: 14030
it has to be presentViewController(...)
instead of presentedViewController(...)
Upvotes: 1