我有以下的警告方法。
static func notifyUser(_ title: String, message: String) -> Void
{
let alert = UIAlertController(title: title,
message: message,
preferredStyle: UIAlertControllerStyle.alert)
let cancelAction = UIAlertAction(title: "OK",
style: .cancel, handler: nil)
alert.addAction(cancelAction)
self.presentViewController(alert, animated: true, completion: nil)
}
我得到一个错误,告诉我在presentViewController
方法中有一个额外的参数animated
,但是当我取出它时,它仍然没有忽略这个错误,然后我被告知completion
是一个额外的参数。
发布于 2016-10-15 13:53:53
let actionSheetController: UIAlertController = UIAlertController(title: "Action Sheet", message: "Swiftly Now! Choose an option!", preferredStyle: .alert)
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
//Just dismiss the action sheet
}
actionSheetController.addAction(cancelAction)
self.present(actionSheetController, animated: true, completion: nil)
发布于 2017-05-13 12:08:21
Swift 3
let alertView = UIAlertController(title: "", message: "your message", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: { (alert) in
})
alertView.addAction(action)
self.present(alertView, animated: true, completion: nil)
发布于 2018-04-23 18:09:10
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
if action {
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: {
(action : UIAlertAction!) in self.navigationController?.popViewController(animated: true)
}))
} else {
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
}
self.present(alert, animated: true, completion: nil)
https://stackoverflow.com/questions/40055488
复制相似问题