【发布时间】:2016-01-26 02:05:27
【问题描述】:
有没有办法将数组“listINeed”传递给处理函数“handleConfirmPressed”?我可以通过将其添加为类变量来做到这一点,但这似乎很老套,现在我想为多个变量执行此操作,所以我需要一个更好的解决方案。
func someFunc(){
//some stuff...
let listINeed = [someObject]
let alert = UIAlertController(title: "Are you sure?", message: alertMessage, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Confirm", style: .Destructive, handler: handleConfirmPressed))
presentViewController(alert, animated: true, completion: nil)
}
func handleConfirmPressed(action: UIAlertAction){
//need listINeed here
}
【问题讨论】:
-
您也可以编写一个方法来返回您的
listNeed对象并使用该方法。 -
@Zhang 我看不出这与将其分配给类变量有什么不同
标签: ios swift uialertcontroller uialertaction