swift中的UIActionSheet将取消按钮放在iOS 7中

Lop*_*ope 12 uiactionsheet ios swift

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

对象版本

在此输入图像描述

Swift版本

在此输入图像描述

这只是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)
Run Code Online (Sandbox Code Playgroud)

知道怎么解决吗?

Lop*_*ope 19

事实证明,这是在提出问题后立即找到答案的另一个案例.

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

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)
Run Code Online (Sandbox Code Playgroud)

不确定他们是否改变了UIActionSheet在Swift中应该如何工作的方式,或者是否是因为它在iOS 8中被弃用而无法修复的错误