
I\'m wondering how I can create a popover with buttons like this.
ANSW
Similar to the other responses, but this is very easy to implement in comparison.
Make your class use the UIActionSheetDelegate.
Example:
@interface ExampleViewController : UIViewController
Then add to your ExampleViewController.mm/m
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { //Get the name of the current pressed button
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Remove"]) {
NSLog(@"Remove this actionSheet"); }
if ([buttonTitle isEqualToString:@"Button 1"]) {
NSLog(@"Button 1 pressed"); }
if ([buttonTitle isEqualToString:@"Button 2"]) {
NSLog(@"Button 2 pressed"); }
if ([buttonTitle isEqualToString:@"Button 3"]) {
NSLog(@"Button 3 pressed"); }
if ([buttonTitle isEqualToString:@"Cancel"]) {
NSLog(@"Cancel clicked (anywhere away from it)"); } }
Now in a button pressed event or where/when you want this to popup call the following:
- (IBAction)aButtonPressed:(id)sender {
NSString *actionSheetTitle = @"Action Sheet"; // Title
NSString *destroyTitle = @"Destroy"; // Button titles
NSString *button1 = @"Button 1";
NSString *button2 = @"Button 2";
NSString *button3 = @"Button 3";
NSString *cancelTitle = @"Cancel";
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:destroyTitle
otherButtonTitles:button1, button2, button3, nil]; [actionSheet showInView:self.view];
}
And more information about this @ : http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html