Showing posts with label UIActionSheet example. Show all posts
Showing posts with label UIActionSheet example. Show all posts

Wednesday, June 12, 2013

UIActionSheet willPresentActionSheet example in Objective C (iOS).

UIActionSheet willPresentActionSheet

Sent to the delegate before an action sheet is presented to the user.

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet

Parameters of [UIActionSheet willPresentActionSheet]
actionSheet
The action sheet that is about to be displayed.

UIActionSheet willPresentActionSheet example.
I assume you have a class which implements the UIActionSheetDelegate protocol and your class is a delegate class of the current UIActionSheet, so in that class you can change the whole title of the UIActionSheet like

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    for (UIView *_currentView in actionSheet.subviews) {
        if ([_currentView isKindOfClass:[UILabel class]]) {
            [((UILabel *)_currentView) setFont:[UIFont boldSystemFontOfSize:15.f]];
        }
    }
}

Example of [UIActionSheet willPresentActionSheet].
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet{

UIImageView* df = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourpic.png"]];
df.center

[actionSheet addSubview:df];
//scale image aspect to fit image view
df.contentMode = UIViewContentModeScaleAspectFit;
//change width of frame
CGRect frame = df.frame;
frame.size.width = 50;
df.frame = frame;


UIActionSheet willPresentActionSheet example.
- (void)notifyShowSuccessActionSheet:(NSNotification *) notification {

NSLog(@\"In ETITMainViewController notifyShowSuccessActionSheet\n\");

UIActionSheet *successActionSheet = [[[UIActionSheet alloc] initWithTitle:nil
delegate:self
   cancelButtonTitle:nil
  destructiveButtonTitle:nil
   otherButtonTitles:@\"Do More\", @\"Done\", @\"Another Test?\", @\"Yet Another\", nil] autorelease];
[successActionSheet setOpaque:NO];
[successActionSheet setAlpha:0.8];
[successActionSheet showFromToolbar:[[self naviController] toolbar]];

}

...and in willPresentActionSheet:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {

UIImageView* successImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"CheckMark64.png\"]];
NSInteger itemPadding;
NSInteger topPadding = [[[actionSheet subviews] objectAtIndex:0] frame].origin.y;

if ([[actionSheet subviews] count] > 1) {
itemPadding = [[[actionSheet subviews] objectAtIndex:1] frame].origin.y
- ([[[actionSheet subviews] objectAtIndex:0] frame].origin.y
   + [[[actionSheet subviews] objectAtIndex:0] frame].size.height);
}
else {
itemPadding = [[[actionSheet subviews] objectAtIndex:0] frame].size.height / 4;
}

// resize action sheet frame to make space for image
[actionSheet setFrame:CGRectMake([actionSheet frame].origin.x,
 [actionSheet frame].origin.y,
 [actionSheet frame].size.width,
 [actionSheet frame].size.height + [successImageView frame].size.height + itemPadding)];

 // re-position buttons
 for (UIControl *button in [actionSheet subviews]) {

[button setFrame:CGRectMake([button frame].origin.x,
[button frame].origin.y + [successImageView frame].size.height + itemPadding,
[button frame].size.width,
[button frame].size.height)];
}

[successImageView setFrame:CGRectMake(([[actionSheet superview] frame].size.width / 2) - [successImageView frame].size.width / 2,
  topPadding,
  [successImageView frame].size.width,
  [successImageView frame].size.height)];

[actionSheet addSubview:successImageView];

}

End of UIActionSheet willPresentActionSheet example article.

UIActionSheet didPresentActionSheet example in Objective C (iOS).

UIActionSheet didPresentActionSheet

Sent to the delegate after an action sheet is presented to the user.

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet

Parameters of [UIActionSheet didPresentActionSheet]
actionSheet
The action sheet that was displayed.

UIActionSheet didPresentActionSheet example.
You can't redraw the border in a different color, so just remove the border and add your own:

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet {
    UIView *contentView = actionSheet.superview;
    UIView *popoverView = contentView.superview;

    UIView *chromeView;
    for (UIView *v in [popoverView subviews]) {
        if (v.subviews.count == 3) {
            chromeView = v;
            break;
        }
    }

    for (UIView *backgroundComponentView in [chromeView subviews]) {
        backgroundComponentView.hidden = YES;

        CGRect componentFrame = backgroundComponentView.frame;  // add your view with this frame
    }
}
Note that this won't work in *will*PresentActionSheet since actionSheet doesn't have a superview set at that point.

Example of [UIActionSheet didPresentActionSheet].
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet{
CGRect rect = CGRectMake(0,0, 320, 480);
UIButton* anImage = [[UIButton alloc] init];
[anImage setTitle:@"GHello worl" forState:UIControlStateNormal];
[anImage setTitle:@"GHello worl dfasd" forState:UIControlStateHighlighted];
[anImage setTitle:@"GHello worl selected" forState:UIControlStateSelected];
//[anImage setBackgroundImage:[UIImage imageNamed:@"photo.png"] forState:UIControlStateNormal];
[anImage addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
rect = CGRectMake(0,0, 320, 220);
anImage.frame =rect;

[actionSheet.superview addSubview:anImage];


[anImage release];
}

End of UIActionSheet didPresentActionSheet example article.

UIActionSheet actionSheetCancel example in Objective C (iOS).

UIActionSheet actionSheetCancel

Sent to the delegate before an action sheet is canceled.

- (void)actionSheetCancel:(UIActionSheet *)actionSheet

Parameters of [UIActionSheet actionSheetCancel]
actionSheet
The action sheet that will be canceled.

Discussion of [UIActionSheet actionSheetCancel]
If the action sheet’s delegate does not implement this method, clicking the cancel button is simulated and the action sheet is dismissed. Implement this method if you need to perform some actions before an action sheet is canceled. An action sheet can be canceled at any time by the system—for example, when the user taps the Home button. The actionSheet:willDismissWithButtonIndex: and actionSheet:didDismissWithButtonIndex: methods are invoked after this method.

UIActionSheet actionSheetCancel example.
To be sure to receive the delegate calls of your UIActionSheet, be sure to indicate in your controller's interface declaration (.h):

@interface YourViewController : UIViewController<UIActionSheetDelegate>

@end
Then in the controller's implementation (.m) :

- (void)actionSheetCancel:(UIActionSheet *)actionSheet {

    NSLog(@"action sheet is about to be cancelled");
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"action sheet was dismissed");
}

Example of [UIActionSheet actionSheetCancel].

-(void) showSheet:(UITabBar *)tabBar displayTitle:(NSString *)name{

    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:name
                                                      delegate:self
                                             cancelButtonTitle:@"Done"
                 destructiveButtonTitle:@"Cancel"otherButtonTitles:nil];

   [menu showFromTabBar:tabBar];
   [menu setBounds:CGRectMake(0,0,320, 700)];

}

// actionsheet delegate protocol item
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex{

    NSLog(@"button index = %d", buttonIndex);
}

- (void)actionSheetCancel:(UIActionSheet *)actionSheet{

    NSLog(@"in action canceled method");
}

End of UIActionSheet actionSheetCancel example article.

UIActionSheet actionSheet willDismissWithButtonIndex example in Objective C (iOS).

UIActionSheet actionSheet willDismissWithButtonIndex

Sent to the delegate before an action sheet is dismissed.

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex

Parameters of [UIActionSheet actionSheet willDismissWithButtonIndex]
actionSheet
The action sheet that is about to be dismissed.
buttonIndex
The index of the button that was clicked. If this is the cancel button index, the action sheet is canceling. If -1, the cancel button index is not set.

Discussion of [UIActionSheet actionSheet willDismissWithButtonIndex]
This method is invoked before the animation begins and the view is hidden.

UIActionSheet actionSheet willDismissWithButtonIndex example.
NSString * videoLink;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIActionSheet *sheet = [[UIActionSheet alloc]

videoLink = \"URL to my movie\";
}
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)indexPath
{
    NSLog(videoLink);
}

Example of [UIActionSheet actionSheet willDismissWithButtonIndex].
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Lanch movie player here with video url at indexPath
//NSString * yourMoviePath = @\"http://vpodcast.dr.dk/DR2/Soeinding/2009/Soeinding_0910272030.mp4\";


// Navigation logic
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * description = [[stories objectAtIndex: storyIndex] objectForKey: @\"summary\"];

UIActionSheet *sheet = [[UIActionSheet alloc]
initWithTitle: NSLocalizedString(description, \"\")
delegate:self
cancelButtonTitle:NSLocalizedString(@\"Cancel\", \"\")
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(@\"Watch video\", \"\"), nil];
[sheet showInView:self.view];
[sheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)indexPath
{
    NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
    switch (indexPath)
{
        case 0:
{
NSString * videoLink = @\"http://vpodcast.dr.dk/DR2/Soeinding/2009/Soeinding_0910132030.mp4\";
NSLog(@\"Playing video: %@\", videoLink);

NSURL *movieURL = [[NSURL URLWithString:videoLink] retain];

MPMoviePlayerController *DingPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[DingPlayer play];
        } break;
    }
    [self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];
}

End of UIActionSheet actionSheet willDismissWithButtonIndex example article.

UIActionSheet actionSheet clickedButtonAtIndex example in Objective C (iOS).

UIActionSheet actionSheet clickedButtonAtIndex

Sent to the delegate when the user clicks a button on an action sheet.

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

Parameters of [UIActionSheet actionSheet clickedButtonAtIndex]
actionSheet
The action sheet containing the button.
buttonIndex
The position of the clicked button. The button indices start at 0.

Discussion of [UIActionSheet actionSheet clickedButtonAtIndex]
The receiver is automatically dismissed after this method is invoked.

UIActionSheet actionSheet clickedButtonAtIndex example.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   

    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"TestSheet"
                                  delegate:self
                                  cancelButtonTitle:@"Cancel"
                                  destructiveButtonTitle:nil
                                  otherButtonTitles: nil];

    [actionSheet addButtonWithTitle:@"one"];
    [actionSheet addButtonWithTitle:@"two"];
    [actionSheet addButtonWithTitle:@"three"];
    [actionSheet addButtonWithTitle:@"four"];
    [actionSheet addButtonWithTitle:@"five"];
    [actionSheet addButtonWithTitle:@"six"];

    [actionSheet showInView:window];
    [actionSheet release];

    return YES;
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"buttonIndex: %d, cancelButtonIndex: %d, firstOtherButtonIndex: %d",
          buttonIndex,
          actionSheet.cancelButtonIndex,
          actionSheet.firstOtherButtonIndex);
}

Example of [UIActionSheet actionSheet clickedButtonAtIndex].
- (IBAction)doSomething:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No Way"
destructiveButtonTitle:@"Yes, I'm Sure!"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
NSLog(@"ok");
}
if (!(buttonIndex == [actionSheet cancelButtonIndex])) {
NSString *msg = nil;

if (nameField.text.length > 0)
msg = [[NSString alloc] initWithFormat:
@"You can breathe easy, %@, everything went OK.",
nameField.text];
else
msg = @"You can breathe easy, everything went OK.";

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Something was done"
message:msg
delegate:self
cancelButtonTitle:@"Phew!"
otherButtonTitles:nil];
[alert show];
[alert release];
[msg release];
}
}

UIActionSheet actionSheet clickedButtonAtIndex example.
- (IBAction) showActionSheet {

    // open a dialog with two custom buttons
    CustomActionSheet *actionSheet = [[CustomActionSheet alloc] initWithTitle:@"UIActionSheet <title>"
                                                             delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Button1", @"Button2", nil];

    [actionSheet setMemberGuid:@"blah blah"];

    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    actionSheet.destructiveButtonIndex = 1;    // make the second button red (destructive)
    [actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
    [actionSheet release];
}

#pragma mark -
#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(CustomActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"clickedButtonAtIndex - memberGuid: %@", actionSheet.memberGuid);

    // the user clicked one of the OK/Cancel buttons
    if (buttonIndex == 0)
    {
        NSLog(@"ok");
    }
    else
    {
        NSLog(@"cancel");
    }
}

End of UIActionSheet actionSheet clickedButtonAtIndex example article.

Wednesday, May 29, 2013

UIActionSheet UIActionSheetStyleBlackOpaque example in Objective C (iOS).

UIActionSheet UIActionSheetStyleBlackOpaque

Specifies the style of an action sheet.

typedef enum {
UIActionSheetStyleAutomatic = -1,
UIActionSheetStyleDefault = UIBarStyleDefault,
UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque,
} UIActionSheetStyle;

Constants
UIActionSheetStyleAutomatic
Takes the appearance of the bottom bar if specified; otherwise, same as UIActionSheetStyleDefault.
UIActionSheetStyleDefault
The default style.
UIActionSheetStyleBlackTranslucent
A black translucent style.
UIActionSheetStyleBlackOpaque
A black opaque style.

UIActionSheet UIActionSheetStyleBlackOpaque example.
        if (existsInInvitedList) {
            eventUserInvitedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
                                                       cancelButtonTitle:@"Cancel"
                                                  destructiveButtonTitle:nil
                                                       otherButtonTitles:@"Join", @"Decline", @"Chat creator", nil];
            eventUserInvitedSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
            [eventUserInvitedSheet showFromTabBar:self.tabBarController.tabBar];
        }else if (existsInAcceptedList){
            eventUserAcceptedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
                                                        cancelButtonTitle:@"Cancel"
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:@"Revoke invite", @"Chat creator", nil];
            eventUserAcceptedSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
            [eventUserAcceptedSheet showFromTabBar:self.tabBarController.tabBar];
        }

Example of [UIActionSheet UIActionSheetStyleBlackOpaque].
UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
  actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
  actionSheet.title = @"some text";//here type your information text
  actionSheet.delegate = self;

  [actionSheet addButtonWithTitle:@"Button 1"];
  [actionSheet addButtonWithTitle:@"Button 2"];
  [actionSheet setCancelButtonIndex:1];

//it is up to you how you show it, I like the tabbar
  [actionSheet showFromTabBar:self.tabBarController.tabBar];

//here lays the trick - you change the size after you've called show
  [actionSheet setBounds:CGRectMake(0,0,320, 480)];

//now create and add your image
   UIImageView *subView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exampleimage.png"]];
   subView.ContentMode = UIViewContentModeScaleAspectFit;
   subView.Frame = CGRectMake(0,130,320,180);//adjust these, so that your text fits in
   [actionSheet addSubview: (subView)];
   [subView release];

  [actionSheet release];    

UIActionSheet UIActionSheetStyleBlackOpaque example.
-(void)ctnPhotoSelection
{
    isMyCtView = YES;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                             delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Take Photo With Camera", @"Select Photo From Library", @"Cancel", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    actionSheet.destructiveButtonIndex = 1;
    [actionSheet showInView:self.view];
    [actionSheet release];
}

End of UIActionSheet UIActionSheetStyleBlackOpaque example article.

UIActionSheet UIActionSheetStyleDefault example in Objective C (iOS).

UIActionSheet UIActionSheetStyleDefault

Specifies the style of an action sheet.

typedef enum {
UIActionSheetStyleAutomatic = -1,
UIActionSheetStyleDefault = UIBarStyleDefault,
UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque,
} UIActionSheetStyle;
Constants
UIActionSheetStyleAutomatic
Takes the appearance of the bottom bar if specified; otherwise, same as UIActionSheetStyleDefault.
UIActionSheetStyleDefault
The default style.
UIActionSheetStyleBlackTranslucent
A black translucent style.
UIActionSheetStyleBlackOpaque
A black opaque style.

UIActionSheet UIActionSheetStyleDefault example.
        if (existsInInvitedList) {
            eventUserInvitedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
                                                       cancelButtonTitle:@"Cancel"
                                                  destructiveButtonTitle:nil
                                                       otherButtonTitles:@"Join", @"Decline", @"Chat creator", nil];
            eventUserInvitedSheet.actionSheetStyle = UIActionSheetStyleDefault;
            [eventUserInvitedSheet showFromTabBar:self.tabBarController.tabBar];
        }else if (existsInAcceptedList){
            eventUserAcceptedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
                                                        cancelButtonTitle:@"Cancel"
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:@"Revoke invite", @"Chat creator", nil];
            eventUserAcceptedSheet.actionSheetStyle = UIActionSheetStyleDefault;
            [eventUserAcceptedSheet showFromTabBar:self.tabBarController.tabBar];
        }

Example of [UIActionSheet UIActionSheetStyleDefault].
UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
  actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
  actionSheet.title = @"some text";//here type your information text
  actionSheet.delegate = self;

  [actionSheet addButtonWithTitle:@"Button 1"];
  [actionSheet addButtonWithTitle:@"Button 2"];
  [actionSheet setCancelButtonIndex:1];

//it is up to you how you show it, I like the tabbar
  [actionSheet showFromTabBar:self.tabBarController.tabBar];

//here lays the trick - you change the size after you've called show
  [actionSheet setBounds:CGRectMake(0,0,320, 480)];

//now create and add your image
   UIImageView *subView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exampleimage.png"]];
   subView.ContentMode = UIViewContentModeScaleAspectFit;
   subView.Frame = CGRectMake(0,130,320,180);//adjust these, so that your text fits in
   [actionSheet addSubview: (subView)];
   [subView release];

  [actionSheet release];    

UIActionSheet UIActionSheetStyleDefault example.
-(void)ctnPhotoSelection
{
    isMyCtView = YES;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                             delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Take Photo With Camera", @"Select Photo From Library", @"Cancel", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    actionSheet.destructiveButtonIndex = 1;
    [actionSheet showInView:self.view];
    [actionSheet release];
}

End of UIActionSheet UIActionSheetStyleDefault example article.

UIActionSheet UIActionSheetStyleAutomatic example in Objective C (iOS).

UIActionSheet UIActionSheetStyleAutomatic

Specifies the style of an action sheet.

typedef enum {
UIActionSheetStyleAutomatic = -1,
UIActionSheetStyleDefault = UIBarStyleDefault,
UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque,
} UIActionSheetStyle;

Constants
UIActionSheetStyleAutomatic
Takes the appearance of the bottom bar if specified; otherwise, same as UIActionSheetStyleDefault.
UIActionSheetStyleDefault
The default style.
UIActionSheetStyleBlackTranslucent
A black translucent style.
UIActionSheetStyleBlackOpaque
A black opaque style.

UIActionSheet UIActionSheetStyleAutomatic example.
        if (existsInInvitedList) {
            eventUserInvitedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
                                                       cancelButtonTitle:@"Cancel"
                                                  destructiveButtonTitle:nil
                                                       otherButtonTitles:@"Join", @"Decline", @"Chat creator", nil];
            eventUserInvitedSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
            [eventUserInvitedSheet showFromTabBar:self.tabBarController.tabBar];
        }else if (existsInAcceptedList){
            eventUserAcceptedSheet = [[UIActionSheet alloc] initWithTitle:eventObject.name delegate:self
                                                        cancelButtonTitle:@"Cancel"
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:@"Revoke invite", @"Chat creator", nil];
            eventUserAcceptedSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
            [eventUserAcceptedSheet showFromTabBar:self.tabBarController.tabBar];
        }

Example of [UIActionSheet UIActionSheetStyleAutomatic].
UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
  actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
  actionSheet.title = @"some text";//here type your information text
  actionSheet.delegate = self;

  [actionSheet addButtonWithTitle:@"Button 1"];
  [actionSheet addButtonWithTitle:@"Button 2"];
  [actionSheet setCancelButtonIndex:1];

//it is up to you how you show it, I like the tabbar
  [actionSheet showFromTabBar:self.tabBarController.tabBar];

//here lays the trick - you change the size after you've called show
  [actionSheet setBounds:CGRectMake(0,0,320, 480)];

//now create and add your image
   UIImageView *subView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exampleimage.png"]];
   subView.ContentMode = UIViewContentModeScaleAspectFit;
   subView.Frame = CGRectMake(0,130,320,180);//adjust these, so that your text fits in
   [actionSheet addSubview: (subView)];
   [subView release];

  [actionSheet release];    

UIActionSheet UIActionSheetStyleAutomatic example.
-(void)ctnPhotoSelection
{
    isMyCtView = YES;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                             delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Take Photo With Camera", @"Select Photo From Library", @"Cancel", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
    actionSheet.destructiveButtonIndex = 1;
    [actionSheet showInView:self.view];
    [actionSheet release];
}

End of UIActionSheet UIActionSheetStyleAutomatic example article.

UIActionSheet showInView example in Objective C (iOS).

UIActionSheet showInView

Displays an action sheet that originates from the specified view.

- (void)showInView:(UIView *)view

Parameters of [UIActionSheet showInView]
view
The view from which the action sheet originates.

Discussion of [UIActionSheet showInView]
The appearance of the action sheet is animated.

On iPad, this method centers the action sheet in the middle of the screen. Generally, if you want to present an action sheet in an iPad application, you should use the showFromRect:inView:animated: method to display the action sheet instead.

UIActionSheet showInView example.
- (void)showOpenOptions
{
UIActionSheet *sheet = [[UIActionSheet alloc]
initWithTitle:NSLocalizedString(@"Open link in external application?", @"Open in external application")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel")
destructiveButtonTitle:NSLocalizedString(@"Open Link", @"Open Link")
otherButtonTitles:nil];

[sheet showInView:self.parentViewController.tabBarController.view];
[sheet release];
}

Example of [UIActionSheet showInView].
UIActionsheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Alarm"
                                    delegate:self
                           cancelButtonTitle:nil
                      destructiveButtonTitle:@"Dismiss"
                               otherButtonTitles:nil];

[actionSheet showInView:[self view]];

UIActionSheet showInView example.
[actionSheet showInView:self.viewController.view]

End of UIActionSheet showInView example article.

UIActionSheet showFromToolbar example in Objective C (iOS).

UIActionSheet showFromToolbar

Displays an action sheet that originates from the specified toolbar.

- (void)showFromToolbar:(UIToolbar *)view

Parameters of [UIActionSheet showFromToolbar]
view
The toolbar from which the action sheet originates.

Discussion of [UIActionSheet showFromToolbar]
The appearance of the action sheet is animated.

On iPad, this method centers the action sheet in the middle of the screen. Generally, if you want to present an action sheet relative to a toolbar in an iPad application, you should use the showFromBarButtonItem:animated: method instead.

UIActionSheet showFromToolbar example.
-(IBAction)buttonsheet {

UIActionSheet *alertView = [[UIActionSheet alloc]
   initWithTitle: @\"File Attributes\"
   delegate:self
   cancelButtonTitle:@\"Cancel\"
   otherButtonTitles:@\"Rename File\", @\"Email File\", nil];
[alertView showFromToolbar: myToolBar];
}

Example of [UIActionSheet showFromToolbar].
//setup an action sheet
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Please make a choice"
delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Do Something", nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque];

//appDelegate
your app delegate name *appDelegate = (your app delegate name *)[[UIApplication sharedApplication] delegate];

//is this a tabbed app?
if([appDelegate.rootApp.tabs count] > 0){
[actionSheet showFromTabBar:[appDelegate.rootApp.rootTabBarController tabBar]];
}else{
if(self.mapToolbar != nil){
[actionSheet showFromToolbar:self.mapToolbar];
}else{
[actionSheet showInView:[self view]];
}
}
[actionSheet release];

UIActionSheet showFromToolbar example.
UIActionSheet *act = [[UIActionSheet alloc] init];
    act.delegate = self;
  
    for (NSString* menu in _menus) {
        [act addButtonWithTitle:menu];
    }
  
    [act addButtonWithTitle:@"Cancel";
    act.cancelButtonIndex = [_menus count];
  
    [act showFromToolbar:self.toolbar];
    [act release];

End of UIActionSheet showFromToolbar example article.

UIActionSheet showFromTabBar example in Objective C (iOS).

UIActionSheet showFromTabBar

Displays an action sheet that originates from the specified tab bar.

- (void)showFromTabBar:(UITabBar *)view

Parameters of [UIActionSheet showFromTabBar]
view
The tab bar from which the action sheet originates.

Discussion of [UIActionSheet showFromTabBar]
The appearance of the action sheet is animated.

On iPad, this method centers the action sheet in the middle of the screen. Generally, if you want to present an action sheet relative to a tab bar in an iPad application, you should use the showFromRect:inView:animated: method instead.

UIActionSheet showFromTabBar example.
YourAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[actionSheet showFromTabBar:delegate.tabBarController.tabBar]

Example of [UIActionSheet showFromTabBar].
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    if (!_testInProgress) return YES;
    // If trying to select this controller then who cares?
    if (viewController == self) return YES; // Or NO. Just don't show the sheet.
    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"You are in the middle of a test. Are you sure you want to switch tabs?"
                                                        delegate:self
                                               cancelButtonTitle:@"Continue Test"
                                          destructiveButtonTitle:@"Abort Test"
                                               otherButtonTitles:nil];
    // Lets cheat and use the tag to store the index of the desired view controller.
    action.tag = [self.tabBarController.viewControllers indexOfObject:viewController];
    [action showFromTabBar:self.tabBarController.tabBar];
    return NO;
}

UIActionSheet showFromTabBar example.
// For detecting taps outside of the alert view
-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer {
    CGPoint p = [gestureRecognizer locationInView:self];
    if (p.y < 0) { // They tapped outside
        [self dismissWithClickedButtonIndex:0 animated:YES];
    }
}

-(void) showFromTabBar:(UITabBar *)view {
    [super showFromTabBar:view];

    // Capture taps outside the bounds of this alert view
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOut:)];
    tap.cancelsTouchesInView = NO; // So that legit taps on the table bubble up to the tableview
    [self.superview addGestureRecognizer:tap];
    [tap release];
}

End of UIActionSheet showFromTabBar example article.

UIActionSheet showFromRect inView animated example in Objective C (iOS).

UIActionSheet showFromRect inView animated

Displays an action sheet that originates from the specified view.

- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated

Parameters of [UIActionSheet showFromRect inView animated]
rect
The portion of view from which to originate the action sheet.
view
The view from which to originate the action sheet.
animated
Specify YES to animate the presentation of the action sheet or NO to present it immediately without any animation effects.

Discussion of [UIActionSheet showFromRect inView animated]
On iPad, this method displays the action sheet in a popover whose arrow points to the specified rectangle of the view. The popover does not overlap the specified rectangle.

UIActionSheet showFromRect inView animated example.
-(void)accessoryPressed:(id)sender{
    //Omitted unnecessary objects

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:titleString delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Upload", nil];
    //actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.tag = ((UIButton*)sender).tag;
    [actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES];
}

Example of [UIActionSheet showFromRect inView animated].
UIDatePicker * pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 270, 220)];
pickerView.datePickerMode = UIDatePickerModeDate;

UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];  

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet addSubview:pickerView];
[actionSheet showFromRect:button.frame inView:button.superview animated:YES];
[actionSheet release];

UIActionSheet showFromRect inView animated example.
CGRect cellRect = cell.bounds;
cellRect.size.width = cell.frame.size.width * 2;
cellRect.origin.x = -(cell.frame.size.width + 10.0);
[_actionSheet showFromRect:cellRect inView:cell animated:YES];

End of UIActionSheet showFromRect inView animated example article.

UIActionSheet showFromRect example in Objective C (iOS).

UIActionSheet showFromRect

Displays an action sheet that originates from the specified view.

- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated

Parameters of [UIActionSheet showFromRect]
rect
The portion of view from which to originate the action sheet.
view
The view from which to originate the action sheet.
animated
Specify YES to animate the presentation of the action sheet or NO to present it immediately without any animation effects.

Discussion of [UIActionSheet showFromRect]
On iPad, this method displays the action sheet in a popover whose arrow points to the specified rectangle of the view. The popover does not overlap the specified rectangle.

UIActionSheet showFromRect example.
-(void)accessoryPressed:(id)sender{
    //Omitted unnecessary objects

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:titleString delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Upload", nil];
    //actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    actionSheet.tag = ((UIButton*)sender).tag;
    [actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES];
}

Example of [UIActionSheet showFromRect].
UIDatePicker * pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 270, 220)];
pickerView.datePickerMode = UIDatePickerModeDate;

UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil]; 

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet addSubview:pickerView];
[actionSheet showFromRect:button.frame inView:button.superview animated:YES];
[actionSheet release];

UIActionSheet showFromRect example.
CGRect cellRect = cell.bounds;
cellRect.size.width = cell.frame.size.width * 2;
cellRect.origin.x = -(cell.frame.size.width + 10.0);
[_actionSheet showFromRect:cellRect inView:cell animated:YES];

End of UIActionSheet showFromRect example article.

UIActionSheet showFromBarButtonItem animated example in Objective C (iOS).

UIActionSheet showFromBarButtonItem animated

Displays an action sheet that originates from the specified bar button item.

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters of [UIActionSheet showFromBarButtonItem animated]
item
The bar button item from which the action sheet originates.
animated
Specify YES to animate the presentation of the action sheet or NO to present it immediately without any animation effects.

Discussion of [UIActionSheet showFromBarButtonItem animated]
On iPad, this method presents the action sheet in a popover and adds the toolbar that owns the button to the popover’s list of passthrough views. Thus, taps in the toolbar result in the action methods of the corresponding toolbar items being called. If you want the popover to be dismissed when a different toolbar item is tapped, you must implement that behavior in your action handler methods.

UIActionSheet showFromBarButtonItem animated example.
-(IBAction) showMoreTools:(id)sender {
    // currently displaying actionsheet?
    if (actionSheet_) {
        [actionSheet_ dismissWithClickedButtonIndex:-1 animated:YES];
        actionSheet_ = nil;
        return;
    }

    actionSheet_ = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Close" otherButtonTitles:@"Add Bookmark", @"Add to Home Screen", @"Print", @"Share", nil];
    actionSheet_.actionSheetStyle = UIActionSheetStyleDefault;
    [popupQuery showFromBarButtonItem:moreTools animated:YES];
    [actionSheet_ release];  // yes, release it. we don't retain it and don't need to
}

Example of [UIActionSheet showFromBarButtonItem animated].
-(void)actionPhotoShare:(id)sender
{
actionSheetShare = [[UIActionSheet alloc] initWithTitle:nil
                                                              delegate:self
                                                     cancelButtonTitle:nil
                                                destructiveButtonTitle:NSLocalizedString(@"ActionSheet_Cancel", @"")
                                                     otherButtonTitles:NSLocalizedString(@"ActionSheet_Email", @""),nil];

if (IS_DEVICE_IPAD) {
    [actionSheetShare showFromBarButtonItem:sender animated:YES];
}else {
    [actionSheetShare showInView:self.view];
}
}

UIActionSheet showFromBarButtonItem animated example.
- (void)promptResetDefaults:(id)sender
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:NSLocalizedString(@"Reset All Defaults", nil)
                                                    otherButtonTitles:nil];

    self.navigationController.navigationBar.userInteractionEnabled = NO;
    [actionSheet showFromBarButtonItem:sender animated:YES];
}

End of UIActionSheet showFromBarButtonItem animated example article.

UIActionSheet showFromBarButtonItem example in Objective C (iOS).

UIActionSheet showFromBarButtonItem

Displays an action sheet that originates from the specified bar button item.

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters
item
The bar button item from which the action sheet originates.
animated
Specify YES to animate the presentation of the action sheet or NO to present it immediately without any animation effects.

Discussion of [UIActionSheet showFromBarButtonItem]
On iPad, this method presents the action sheet in a popover and adds the toolbar that owns the button to the popover’s list of passthrough views. Thus, taps in the toolbar result in the action methods of the corresponding toolbar items being called. If you want the popover to be dismissed when a different toolbar item is tapped, you must implement that behavior in your action handler methods.

UIActionSheet showFromBarButtonItem example.
-(IBAction) showMoreTools:(id)sender {
    // currently displaying actionsheet?
    if (actionSheet_) {
        [actionSheet_ dismissWithClickedButtonIndex:-1 animated:YES];
        actionSheet_ = nil;
        return;
    }

    actionSheet_ = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Close" otherButtonTitles:@"Add Bookmark", @"Add to Home Screen", @"Print", @"Share", nil];
    actionSheet_.actionSheetStyle = UIActionSheetStyleDefault;
    [popupQuery showFromBarButtonItem:moreTools animated:YES];
    [actionSheet_ release];  // yes, release it. we don't retain it and don't need to
}

Example of [UIActionSheet showFromBarButtonItem].
-(void)actionPhotoShare:(id)sender
{
actionSheetShare = [[UIActionSheet alloc] initWithTitle:nil
                                                              delegate:self
                                                     cancelButtonTitle:nil
                                                destructiveButtonTitle:NSLocalizedString(@"ActionSheet_Cancel", @"")
                                                     otherButtonTitles:NSLocalizedString(@"ActionSheet_Email", @""),nil];

if (IS_DEVICE_IPAD) {
    [actionSheetShare showFromBarButtonItem:sender animated:YES];
}else {
    [actionSheetShare showInView:self.view];
}
}

UIActionSheet showFromBarButtonItem example.
- (void)promptResetDefaults:(id)sender
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:NSLocalizedString(@"Reset All Defaults", nil)
                                                    otherButtonTitles:nil];

    self.navigationController.navigationBar.userInteractionEnabled = NO;
    [actionSheet showFromBarButtonItem:sender animated:YES];
}

End of UIActionSheet showFromBarButtonItem example article.

UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles example in Objective C (iOS).

UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles

Initializes the action sheet using the specified starting parameters.

- (id)initWithTitle:(NSString *)title delegate:(id < UIActionSheetDelegate >)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...

Parameters of [UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles]
title
A string to display in the title area of the action sheet. Pass nil if you do not want to display any text in the title area.
delegate
The receiver’s delegate object. Although this parameter may be nil, the delegate is used to respond to taps in the action sheet and should usually be provided.
cancelButtonTitle
The title of the cancel button. This button is added to the action sheet automatically and assigned an appropriate index, which is available from the cancelButtonIndex property. This button is displayed in black to indicate that it represents the cancel action. Specify nil if you do not want a cancel button or are presenting the action sheet on an iPad.[UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles]
destructiveButtonTitle
The title of the destructive button. This button is added to the action sheet automatically and assigned an appropriate index, which is available from the destructiveButtonIndex property. This button is displayed in red to indicate that it represents a destructive behavior. Specify nil if you do not want a destructive button.
otherButtonTitles, ...
The titles of any additional buttons you want to add. This parameter consists of a nil-terminated, comma-separated list of strings. For example, to specify two additional buttons, you could specify the value @"Button 1", @"Button 2", nil.

Return Value of [UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles]
A newly initialized action sheet.

Discussion of [UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles]
The action sheet automatically sets the appearance of the destructive and cancel buttons. If the action sheet contains only one button, it does not apply the custom colors associated with the destructive and cancel buttons.

UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles example.
UIActionSheet *alert = [[UIActionSheet alloc] initWithTitle: titleString
                              delegate: self
                              cancelButtonTitle: nil
                              destructiveButtonTitle: nil
                              otherButtonTitles: nil];

Example of [UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles].
- (void)showActionSheetWithButtons:(NSArray *)buttons withTitle:(NSString *)title {

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle: title
                                                             delegate: self
                                                    cancelButtonTitle: nil
                                               destructiveButtonTitle: nil
                                                    otherButtonTitles: nil];

    for (NSString *title in buttons) {
        [actionSheet addButtonWithTitle: title];
    }

    [actionSheet addButtonWithTitle: @"Cancel"];
    [actionSheet setCancelButtonIndex: [buttons count]];
    [actionSheet showInView:self.view];
}

UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles example.
NSArray *array = [[NSArray alloc] initWithObjects:
                      [NSString stringWithString:@"1st Button"],
                      [NSString stringWithString:@"2nd Button"],
                      [NSString stringWithString:@"3rd Button"],
                      [NSString stringWithString:@"4th Button"],
                      nil];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title Here"
                                                             delegate:self
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];

    for (int i = 0; i < [array count]--; i++) {

        [actionSheet addButtonWithTitle:[array objectAtIndex:i]];

    }

    [actionSheet addButtonWithTitle:@"Cancel"];
    actionSheet.cancelButtonIndex = array.count;

    [actionSheet showInView:self.view];

End of UIActionSheet initWithTitle delegate cancelButtonTitle destructiveButtonTitle otherButtonTitles example article.

UIActionSheet initWithTitle example in Objective C (iOS).

UIActionSheet initWithTitle

Initializes the action sheet using the specified starting parameters.

- (id)initWithTitle:(NSString *)title delegate:(id < UIActionSheetDelegate >)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...

Parameters of [UIActionSheet initWithTitle]
title
A string to display in the title area of the action sheet. Pass nil if you do not want to display any text in the title area.
delegate
The receiver’s delegate object. Although this parameter may be nil, the delegate is used to respond to taps in the action sheet and should usually be provided.[UIActionSheet initWithTitle]
cancelButtonTitle
The title of the cancel button. This button is added to the action sheet automatically and assigned an appropriate index, which is available from the cancelButtonIndex property. This button is displayed in black to indicate that it represents the cancel action. Specify nil if you do not want a cancel button or are presenting the action sheet on an iPad.
destructiveButtonTitle  [UIActionSheet initWithTitle]
The title of the destructive button. This button is added to the action sheet automatically and assigned an appropriate index, which is available from the destructiveButtonIndex property. This button is displayed in red to indicate that it represents a destructive behavior. Specify nil if you do not want a destructive button.
otherButtonTitles, ...
The titles of any additional buttons you want to add. This parameter consists of a nil-terminated, comma-separated list of strings. For example, to specify two additional buttons, you could specify the value @"Button 1", @"Button 2", nil.

Return Value of [UIActionSheet initWithTitle]
A newly initialized action sheet.

Discussion of [UIActionSheet initWithTitle]
The action sheet automatically sets the appearance of the destructive and cancel buttons. If the action sheet contains only one button, it does not apply the custom colors associated with the destructive and cancel buttons.

UIActionSheet initWithTitle example.
UIActionSheet *alert = [[UIActionSheet alloc] initWithTitle: titleString
                              delegate: self
                              cancelButtonTitle: nil
                              destructiveButtonTitle: nil
                              otherButtonTitles: nil];

Example of [UIActionSheet initWithTitle].
- (void)showActionSheetWithButtons:(NSArray *)buttons withTitle:(NSString *)title {

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle: title
                                                             delegate: self
                                                    cancelButtonTitle: nil
                                               destructiveButtonTitle: nil
                                                    otherButtonTitles: nil];

    for (NSString *title in buttons) {
        [actionSheet addButtonWithTitle: title];
    }

    [actionSheet addButtonWithTitle: @"Cancel"];
    [actionSheet setCancelButtonIndex: [buttons count]];
    [actionSheet showInView:self.view];
}

UIActionSheet initWithTitle example.
NSArray *array = [[NSArray alloc] initWithObjects:
                      [NSString stringWithString:@"1st Button"],
                      [NSString stringWithString:@"2nd Button"],
                      [NSString stringWithString:@"3rd Button"],
                      [NSString stringWithString:@"4th Button"],
                      nil];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title Here"
                                                             delegate:self
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];

    for (int i = 0; i < [array count]--; i++) {

        [actionSheet addButtonWithTitle:[array objectAtIndex:i]];

    }

    [actionSheet addButtonWithTitle:@"Cancel"];
    actionSheet.cancelButtonIndex = array.count;

    [actionSheet showInView:self.view];

End of UIActionSheet initWithTitle example article.

UIActionSheet dismissWithClickedButtonIndex animated example in Objective C (iOS).

UIActionSheet dismissWithClickedButtonIndex animated

Dismisses the action sheet immediately using an optional animation.

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

Parameters of [UIActionSheet dismissWithClickedButtonIndex animated]
buttonIndex
The index of the button that was clicked. Button indices start at 0.
animated
Specify YES to animate the dismissal of the action sheet or NO to remove the action sheet without an animation.

Discussion of [UIActionSheet dismissWithClickedButtonIndex animated]
You can use this method to dismiss the action sheet programmatically as needed. The action sheet also calls this method itself in response to the user tapping one of the buttons in the action sheet.

In iOS 4.0, you may want to call this method whenever your application moves to the background. An action sheet is not dismissed automatically when an application moves to the background. This behavior differs from previous versions of the operating system, where they were canceled automatically when the application was terminated. Dismissing the action sheet gives your application a chance to save changes or abort the operation and perform any necessary cleanup in case your application is terminated later.

UIActionSheet dismissWithClickedButtonIndex animated example.
-(void)dismissActionSheet {
   [sheet dismissWithClickedButtonIndex:0 animated:YES];
}

Example of [UIActionSheet dismissWithClickedButtonIndex animated].
-(void)dismissSheet{
    if (self.actionSheet){
        [self.actionSheet dismissWithClickedButtonIndex:0 animated:NO];
    }
}

-(void)viewDidLoad{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissSheet) name:UIApplicationWillResignActiveNotification object:nil];
        // Your other setup code
}

UIActionSheet dismissWithClickedButtonIndex animated example.
    -(void) dismissActionSheet:(id)sender {
        UIActionSheet *actionSheet =  (UIActionSheet *)[(UIView *)sender superview];
        [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    }

End of UIActionSheet dismissWithClickedButtonIndex animated example article.