我正在将我的应用程序从 objective-c 重写为 Swift,我注意到 UIActionSheet 在 Swift 版本中的行为与在 obj-c 版本中的行为不同。
Obj-c 版本
快速版本
这仅在 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/