UIActionSheet在快速放置取消button顶部iOS 7

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

Obj-c版本

在这里输入图像说明

Swift版本

在这里输入图像说明

这只是在iOS 7上的一个问题,它适用于Swift和Obj-C版本的iOS 8上的正常工作(意味着取消在底部)

这是相关的一段代码:

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

任何想法如何解决它?

原来,这是另外一个提问后find答案的案例。

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

 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中被弃用而无人修复

以下是我在viewDidLoad()上所做的或button操作将代码如下所示:

 let actionSheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Done", otherButtonTitles: "Yes", "No") actionSheet.showInView(self.view) 

然后为他们的行为添加另一个function,如:

 func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) { switch buttonIndex{ case 0: NSLog("Done"); break; case 1: NSLog("Cancel"); break; case 2: NSLog("Yes"); break; case 3: NSLog("No"); break; default: NSLog("Default"); break; //Some code here.. } }