Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIActionsheet未显示运行iOS7的iPad上的所有按钮_Ios_Ipad_Ios7_Swift_Uiactionsheet - Fatal编程技术网

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

UIActionsheet未显示运行iOS7的iPad上的所有按钮,ios,ipad,ios7,swift,uiactionsheet,Ios,Ipad,Ios7,Swift,Uiactionsheet,UIActionSheet实例在运行iOS7的iPad上无法正确显示。出于某种原因,它们会显示“取消”按钮,而不显示最后一个按钮。同样的代码在iOS8上运行良好 您可能希望取消按钮被忽略,因为点击屏幕上的其他位置将关闭操作表。有人知道为什么会这样吗 两种情况下使用的代码完全相同: // Create UIActionSheet let mapOptions = UIActionSheet(title: "Select map type", delegate: self, cancelBu

UIActionSheet实例在运行iOS7的iPad上无法正确显示。出于某种原因,它们会显示“取消”按钮,而不显示最后一个按钮。同样的代码在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)

我可以通过避免默认的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)

我和斯威夫特面临着同样的问题。你的回答救了我。 我发现您仍然可以使用这个init方法(使用cancel按钮nil)使代码更加简洁

let mapOptions = UIActionSheet(title: "Select map type", delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil, otherButtonTitles: "Standard", "Hybrid", "Satellite")
然后用你提供的线路

mapOptions.cancelButtonIndex = mapOptions.addButtonWithTitle("Cancel")
(我没有足够的声誉来添加评论,所以请写在这里。)