gpt4 book ai didi

swift - 如何将用户数据传递给

转载 作者:行者123 更新时间:2023-11-28 09:20:24 24 4
gpt4 key购买 nike

我想将数据传递给 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com