我想把数据传递给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"
}
最佳答案
使用闭包
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
}))
关于swift - 如何将用户数据传递给,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25195178/