swift - UIAlertAction 错误

标签 swift

我正在尝试向 UIAlertController 添加一些操作,但是当我向其传递闭包时出现错误。我想将该闭包作为操作的处理程序传递,但我收到一条错误消息。 enter image description here

 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/

相关文章:

swift - 类型 '...' 的值在赋值中不符合 '...'

swift - 如果 (Bools = true) 不执行 -Swift

ios - 在每个 View Controller 中自定义 UITabBar.appearance [Swift]

json - 使用 Swift 解析 JSON

ios - SpriteKit 碰撞检测中 SKSpriteNodes 之间的间隙

arrays - 将 Swift Array 的内容复制到 Struct embedded Tuple

swift - final Class 和 Class 有什么区别?

ios - 如何停用我的限制?

ios - UITableView Cell 只需点击几下即可呈现 View Controller

ios - 一直可靠工作的时间戳函数只是导致了 EXC_BAD_INSTRUCTION