我正在创建一个简单的提醒,但它向我显示此错误。
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)
}
}
答案 0 :(得分:1)
必须是presentViewController(...)
而不是 presentsViewController(...)
答案 1 :(得分:0)
这是什么,适合我使用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){}
});
}