我正在尝试向 UIAlertController 添加一些操作,但是当我向其传递闭包时出现错误。我想将该闭包作为操作的处理程序传递,但我收到一条错误消息。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
let optionMenu = UIAlertController(title: nil, message: "What do you want to do?", preferredStyle: .ActionSheet)
let cancel = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
optionMenu.addAction(cancel)
self.presentViewController(optionMenu, animated: true, completion: nil)
let callActionHandler = { (action:UIAlertAction) -> Void in
let alertMessage = UIAlertController(title: "No service", message: "Sorry the phone option is not working right now, try again later", preferredStyle: .Alert)
alertMessage.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
self.presentViewController(alertMessage, animated: true, completion: nil)
}
let callAction = UIAlertAction(title: "Call " + "123-000-\(indexPath.row)", style: UIAlertActionStyle.Default , handler: callActionHandler)
optionMenu.addAction(callAction)
}
最佳答案
已解决。您只错过了!
。
更改以下行
let callActionHandler = { (action:UIAlertAction) -> 无效
与
let callActionHandler = { (action:UIAlertAction!) -> 无效
就是这样!
关于swift - UIAlertAction 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31468318/