UIAlertAction错误

时间:2015-07-17 04:17:54

标签: 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)


    }

1 个答案:

答案 0 :(得分:1)

解决。只有!你错过了。 更改以下行

let callActionHandler = { (action:UIAlertAction) -> Void in

let callActionHandler = { (action:UIAlertAction!) -> Void in

就是这样!