Skip to content

Instantly share code, notes, and snippets.

Created December 21, 2012 19:13
Show Gist options
  • Save anonymous/4355052 to your computer and use it in GitHub Desktop.
Save anonymous/4355052 to your computer and use it in GitHub Desktop.
Suggestion for a better UIActionSheet API.
// Action Sheet API with target/selector
ECActionSheet *actionSheet = [[ECActionSheet alloc] initWithTitle:@"Title" cancelButtonTitle:@"Cancel"];
[actionSheet addDestructiveButtonWithTitle:@"Destructive Button" target:self selector:@selector(destructiveButtonPressed)];
[actionSheet addButtonWithTitle:@"Button One" target:self selector:@selector(buttonOnePressed)];
[actionSheet addButtonWithTitle:@"Button Two" target:self selector:@selector(buttonTwoPressed)];
[actionSheet showInView:self.view];
// Action Sheet API with blocks
ECActionSheet *actionSheet = [[ECActionSheet alloc] initWithTitle:@"Title" cancelButtonTitle:@"Cancel"];
[actionSheet setDestructiveButtonWithTitle:@"Destructive Button" onTapped:^{
// do something when destructive button is tapped
}];
[actionSheet addButtonWithTitle:@"Button One" onTapped:^{
// do something when button one is tapped
}];
[actionSheet addButtonWithTitle:@"Button Two" onTapped:^{
// do something when button one is tapped
}];
[actionSheet showInView:self.view];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment