我正致力于在 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)
如何处理按钮点击事件?? 我是否需要以任何方式使用 handle 参数??
最佳答案
你可以尝试这样的事情:
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)
关于ios - 在 SWIFT 中处理 UIActionSheet 上的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24487425/