Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActionsheet not displaying all buttons on iPads running iOS7

Instances of UIActionSheet don't display correctly on iPads running iOS7. For some reason, they display the cancel button and leave off the last button. The same code works fine on iOS8.

You would expect the cancel button to be ignored, given that tapping elsewhere on the screen will close the action sheet. Does anyone know why this is the case?

Exactly the same code is used in both cases:

// 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

like image 340
Ian Avatar asked Feb 11 '23 12:02

Ian


1 Answers

I was able to solve the problem by avoiding the default UIActionSheet constructor and adding buttons individually. This - and making sure the cancel button is added last - resolves the issue.

// 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)
like image 122
Ian Avatar answered Feb 16 '23 03:02

Ian