我正在为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)