UIActionsheet在运行iOS7的iPad上未显示所有按钮

4

在运行 iOS7 的iPad上,UIActionSheet 实例的显示效果不正确。由于某种原因,它们会显示取消按钮,并且遗漏最后一个按钮。相同的代码在iOS8上运行良好。

你可能期望取消按钮被忽略,因为在屏幕其他位置轻触将关闭操作表。有人知道这是为什么吗?

两种情况下使用完全相同的代码:

// Create UIActionSheet    
let mapOptions = UIActionSheet(title: "Select map type", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Standard", "Hybrid", "Satellite")

// Display from bar button
mapOptions.showFromBarButtonItem(self.mapTypeButton, animated: true)

comparison of UIActionSheet instances on iOS 7 and 8

2个回答

5

我能通过避免使用默认的UIActionSheet构造器并逐个添加按钮来解决这个问题。这样做,确保取消按钮被最后添加,就可以解决这个问题。

// Create the UIActionSheet
var mapOptions = UIActionSheet()
mapOptions.title = "Select map type"
mapOptions.addButtonWithTitle("Standard")
mapOptions.addButtonWithTitle("Hybrid")
mapOptions.addButtonWithTitle("Satellite")

// Add a cancel button, and set the button index at the same time
mapOptions.cancelButtonIndex = mapOptions.addButtonWithTitle("Cancel")
mapOptions.delegate = self

// Display the action sheet
mapOptions.showFromBarButtonItem(self.mapTypeButton, animated: true)

3

我遇到了和Swift相关的同样问题。你的回答救了我。我发现,你仍然可以使用这个init方法(将取消按钮设置为nil)来使你的代码更加简洁。

let mapOptions = UIActionSheet(title: "Select map type", delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil, otherButtonTitles: "Standard", "Hybrid", "Satellite")

然后使用您提供的代码行

mapOptions.cancelButtonIndex = mapOptions.addButtonWithTitle("Cancel")

(我的声望不够高,无法添加评论,所以在这里写。)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接