ios - swift 中的 UIActionSheet 将取消按钮放在 iOS 7 的顶部

标签 ios swift uiactionsheet

我正在将我的应用程序从 objective-c 重写为 Swift,我注意到 UIActionSheet 在 Swift 版本中的行为与在 obj-c 版本中的行为不同。

Obj-c 版本

enter image description here

快速版本

enter image description here

这仅在 iOS 7 上存在问题,它在 iOS 8 上对于 Swift 和 Obj-c 版本都工作正常(意味着取消在底部)

这是一段相关的代码:

var sheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil)
sheet.addButtonWithTitle("Camera")
sheet.addButtonWithTitle("Photo Library")
sheet.showInView(self.controller.view)

知道如何解决吗?

最佳答案

原来这又是一问即答的案例。

我所要做的就是将“取消”按钮添加为另一个按钮,然后指定其索引:

var sheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil)
sheet.addButtonWithTitle("Camera")
sheet.addButtonWithTitle("Photo Library")
sheet.addButtonWithTitle("Cancel")
sheet.cancelButtonIndex = 2
sheet.showInView(self.controller.view)

不确定他们是否改变了 UIActionSheet 在 Swift 中的工作方式,或者它是否是一个没人关心修复的错误,因为它在 iOS 8 中已经被弃用了

关于ios - swift 中的 UIActionSheet 将取消按钮放在 iOS 7 的顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28116417/

相关文章:

ios - URLsession 委托(delegate)函数出错

ios - Swift:如何为一个 Estimote Beacon 配置 ESTBeaconConnection?

ios - 重新启用操作表操作

ios - 带有禁用按钮的 UIActionSheet?

iOS eureka-forms LabelRow 隐藏条件未评估

ios - 在多个 UIViewcontroller 应用程序中添加广告横幅

iphone - 无法设置UITabBarController的moreNavigationController的右键

ios - Couchbase lite,搜索查询花费很长时间

swift - OSX : Delegating between a NSWindowController and a NSViewController

ios - UIPopover 如何使用这样的按钮制作弹出窗口?