我发现void返回警报但未找到字符串警报返回。 尝试Void to String
// return Void Alert
func returnAlert(title: String!, message: String! ,success: (() -> Void)? , cancel: (() -> Void)?) {
dispatch_async(dispatch_get_main_queue(), {
let alertController = UIAlertController(title:title,
message: "",
preferredStyle: UIAlertControllerStyle.Alert)
self.newQtyField = UITextField()
self.newQtyField.keyboardType = .NumberPad
func addTextField(textField: UITextField!){
// add the text field and make the result global
let row = self.array[Int(message)!]
textField.text = String(row.pbQty!)
self.newQtyField = textField
}
let cancelLocalized = NSLocalizedString("cancel", tableName: "activity", comment:"")
let okLocalized = NSLocalizedString("ok", tableName: "Localizable", comment:"")
let cancelAction: UIAlertAction = UIAlertAction(title: cancelLocalized,
style: .Cancel) {
action -> Void in cancel?()
}
let successAction: UIAlertAction = UIAlertAction(title: okLocalized,
style: .Default) {
action -> Void in success?()
}
alertController.addTextFieldWithConfigurationHandler(addTextField)
alertController.addAction(cancelAction)
alertController.addAction(successAction)
self.presentViewController(alertController, animated: true, completion: nil)
})
}
//底部呼唤乐趣|我认为成功:{()成功:{textfield,但不工作如何...需要你的帮助
returnAlert("title", message: "msg", success: { () -> Void in
})
{ () -> Void in
print("user canceled")
}
答案 0 :(得分:0)
很难理解你在问题中所说的内容。
您应该将方法定义更改为:
func returnAlert(title: String!, message: String! ,success: ((text:String) -> Void)? , cancel: (() -> Void)?) {
并更改successAction
以返回UITextField的值:
let successAction: UIAlertAction = UIAlertAction(title: okLocalized,
style: .Default) { action in
success?(text: self.newQtyField.text!)
}