如何将用户数据传递给

时间:2014-08-08 02:20:51

标签: swift alert

我想将数据传递给driveMeTo处理程序。我该怎么办? 请参阅以下代码:

    var alert = UIAlertController(title: annotation.title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel, handler:handleCancel))
    alert.addAction(UIAlertAction(title: "Y aller", style: UIAlertActionStyle.Default, handler:driveMeTo))
    self.presentViewController(alert, animated: true, completion: nil)



func driveMeTo(alertView: UIAlertAction!)
{
  println "Where I want the data passed"
}

1 个答案:

答案 0 :(得分:0)

使用闭包

var foo = "test"
alert.addAction(UIAlertAction(title: "Y aller",
    style: UIAlertActionStyle.Default, 
    handler:{(action : UIAlertAction!) -> Void in 
        println(foo) // you can refer to variable in outer scope
    }))