swift中的UIActionSheet将取消按钮放在iOS 7中 [英] UIActionSheet in swift puts Cancel button top in iOS 7
问题描述
我正在将我的应用程序从目标c重写为Swift,我注意到UIActionSheet在Swift版本中的行为与在obj-c版本中的行为不同。
I am in the process of rewriting my app from objective c to Swift and I noticed that UIActionSheet behaves differently in Swift version than in obj-c version.
Obj -c version
Obj-c version
Swift版
这仅在iOS 7上存在问题,在iOS 8上工作正常(意味着取消在底部) Swift和Obj-c版本
This is a problem only on iOS 7, it works fine (meaning the cancel is on the bottom) on iOS 8 for both Swift and Obj-c versions
以下是相关的代码:
var sheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil)
sheet.addButtonWithTitle("Camera")
sheet.addButtonWithTitle("Photo Library")
sheet.showInView(self.controller.view)
任何想法如何修复它?
推荐答案
原来这是另一个在提出问题后立即找到答案的情况。
Turns out this was yet another case of finding answer right after asking the question.
我所要做的只是将取消按钮添加为另一个按钮,然后指定其索引:
All I had to do was add Cancel button as another button and then specify its index:
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中被弃用了
Not sure if they changed the way how UIActionSheet is supposed to work in Swift or if it's bug that nobody cares to fix since it's deprecated in iOS 8 anyway
这篇关于swift中的UIActionSheet将取消按钮放在iOS 7中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!