Last active
August 29, 2015 14:17
-
-
Save advantis/c965dce110538ac66063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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