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

标签 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"
}

最佳答案

使用闭包

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/

相关文章:

ios - NSURL/NSURLRequest 意外地为零

javascript - 使用 phonegap 和 android 的 javascript 警报中的特殊字符

swift - 如何创建 iflix 主页布局

ios - NavigationController 在 popToRootViewController 之后不重新加载 tableView 数据

ios - Azure 空间 anchor 创建观察程序导致断言错误

ios - React Native (0.63) 警报在 IOS 中自动消失

javascript - 创建不显示的alert()方法 - javascript

asp.net - 关于 javascript 警报 asp.net c# 的问题

swift - 为什么我的 UIAlert 上的按钮重复?

Swift Firebase 数据库错误处理