Skip to content

Instantly share code, notes, and snippets.

@advantis
Last active August 29, 2015 14:17
Show Gist options
  • Save advantis/c965dce110538ac66063 to your computer and use it in GitHub Desktop.
Save advantis/c965dce110538ac66063 to your computer and use it in GitHub Desktop.
import UIKit
typealias SheetAction = () -> Void
class ActionSheet: UIActionSheet {
private var actions = [SheetAction]()
convenience init() {
self.init(frame: CGRectZero)
delegate = self
}
override func addButtonWithTitle(title: String) -> Int {
return addButtonWithTitle(title) {}
}
func addButtonWithTitle(title: String, action: SheetAction) -> Int {
let index = super.addButtonWithTitle(title)
actions.insert(action, atIndex: index)
return index
}
}
extension ActionSheet: UIActionSheetDelegate {
func actionSheet(_: UIActionSheet, clickedButtonAtIndex index: Int) {
// Check for the case of tapping outside an action sheet on iPad
if index < actions.count {
actions[index]()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment