ios - 在 SWIFT 中处理 UIActionSheet 上的事件

标签 ios swift uiactionsheet ios8 uiactionsheetdelegate

我正致力于在 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/

相关文章:

iPhone的 "Add to Home Screen"定制?

iphone - 同一位置坐标中的多个注释( MKAnnotationView )

ios - 如何将 NSMutableDictionary 值传递给 Storyboard 中的多个 Controller ?

iphone - 按下 UIBarButton 时 UIAction 表不会消失

iphone - 添加 iPhone 共享按钮

ios - 核心数据和累积轻量级迁移

ios - 恒定速度,同时仍然能够施加脉冲

ios - 如何以正确的方向旋转图像

swift - os_log_debug 导入 o​​s 或 os.log 时未解析的标识符

objective-c - (iOS/Objective-C)有条件向UIActionSheet添加不同按钮的更好方法吗?