在 SWIFT 中处理 UIActionSheet 上的事件
Posted
技术标签:
【中文标题】在 SWIFT 中处理 UIActionSheet 上的事件【英文标题】:Handling events on UIActionSheet in SWIFT 【发布时间】:2014-06-30 09:55:39 【问题描述】:我正在 SWIFT 中为 ios8 创建 UIActionSheet。我有一个工作代码,但我一直在处理操作表的按钮点击。
我当前的代码是:
var actionSheet = UIAlertController(title: "Publish this Image ?", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
actionSheet.addAction(UIAlertAction(title: "Tweet", style: UIAlertActionStyle.Cancel, handler: nil))
actionSheet.addAction(UIAlertAction(title: "WhatsApp", style: UIAlertActionStyle.Default, handler: nil))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Destructive, handler: nil))
self.presentViewController(actionSheet, animated: true, completion: nil)
如何处理按钮点击事件? 我需要以任何方式使用句柄参数吗??
【问题讨论】:
【参考方案1】:你可以试试这样的:
var actionSheet = UIAlertController(title: "Publish this Image ?", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
actionSheet.addAction(UIAlertAction(title: "Tweet", style: UIAlertActionStyle.Default, handler: (ACTION :UIAlertAction!)in
//your code here...
))
actionSheet.addAction(UIAlertAction(title: "WhatsApp", style: UIAlertActionStyle.Default, handler: (ACTION :UIAlertAction!)in
//your code here...
))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(actionSheet, animated: true, completion: nil)
【讨论】:
以上是关于在 SWIFT 中处理 UIActionSheet 上的事件的主要内容,如果未能解决你的问题,请参考以下文章
Swift:如何通过单击按钮 UITableVieCell 创建 UIActionSheet
Swift UIAlertView/UIActionSheet
swift 创建第一个UIAlertView 和UIActionSheet