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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With