【发布时间】:2018-12-27 12:33:27
【问题描述】:
您好,我刚开始学习 Swift。我只是学习ios开发的初学者。
func showOkay() {
let title = NSLocalizedString("a title", comment: "")
let message = NSLocalizedString("msg", comment: "")
let cansal = NSLocalizedString("cancel", comment: "")
let ok = NSLocalizedString("ok", comment: "")
let alertController = UIAlertController (title: title, message: message, preferredStyle: .alert)
let cancelAlertAction = UIAlertAction (title : cansal, style : .cancel) {
_ in print("cancel") // i don't understand this line . its just a print or somthing else. why i cant use print here.
}
let okAction = UIAlertAction(title: ok , style : .default) {
_ in print("ok") // i don't understand this line. its just a print or somthing else. why i cant use print here.
}
alertController.addAction(cancelAlertAction)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
@IBAction func btnAction(_ sender: Any) {
showOkay()
}
如果我使用print(),他们只会给我类似的错误
无法将类型 '() -> ()' 的值转换为预期的参数类型 '((UIAlertAction) -> Void)?'
【问题讨论】:
标签: ios iphone swift cocoa-touch