views:

291

answers:

2

On the iPhone, in the Calendar App when you press the "Delete Event" button a confirmation slides in from the bottom. Does anyone know of any example code for this, or is it just a short view presented modally with a custom background?

If this is made using a custom view, do you know where I can get a background graphic the same as the one used in the Calendar App?

Thanks in advance!

NB: I am not talking about a UIAlertView dialog box, but the slide-in confirmation with multiple buttons.

+1  A: 

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"destructive" otherButtonTitles:@"other", nil]; [actionSheet showInView:self.view]; [actionSheet release];

nathanjosiah
+3  A: 

UIActionSheet is what you are looking for.

Here is some code example to get you started with:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Save photo?" delegate:self cancelButtonTitle:@"No" destructiveButtonTitle:@"Yes" otherButtonTitles:nil];
 [actionSheet showInView:self.view];
 [actionSheet release];

This will slide in an action sheet from the bottom. It has 2 buttons. Yes and No.

When a user selects any button the actionSheet:didDismissWithButtonIndex: method gets called

-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
//your code here
}

Your controller class will have to subscribe to the < UIActionSheetDelegate > protocol

Hope this helps!

Mihir Mathuria
Lovely, thanks for the quick answer. Here was I thinking Action Sheets were only on the iPad!
crunchyt