UIActionSheet

Image

This is a simple ActionSheet demo for iOS beginners.

Image

You can Find  Code Here

ActionSheetDemoViewController.h

#import <UIKit/UIKit.h>

@interface ActionSheetDemoViewController : UIViewController<UIActionSheetDelegate>

@end

ActionSheetDemoViewController.m

#import “ActionSheetDemoViewController.h”

@interface ActionSheetDemoViewController ()
-(void)showActionSheet:(id)sender;
@end

@implementation ActionSheetDemoViewController

-(void)showActionSheet:(id)sender;
{
NSString * actionSheetTitle = @”Action Sheet Demo”;
NSString * destrcutiveTitle = @”Destructive Title”;
NSString * other1= @”Other Button 1″;
NSString * other2 = @”Other Button 2″;
NSString * other3 = @”Other Button 3″;
NSString * cancelTitle= @”Cancel Button”;

UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:actionSheetTitle
delegate:self
cancelButtonTitle:cancelTitle
destructiveButtonTitle:destrcutiveTitle
otherButtonTitles:other1, other2, other3, nil];
actionSheet.actionSheetStyle=UIActionSheetStyleAutomatic;
[actionSheet showInView:self.view];

}
– (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{

NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

if ([buttonTitle isEqualToString:@”Destructive Title”])
{
UIActionSheet * desactionsht=[[UIActionSheet alloc]initWithTitle:@”Destructive pressed” delegate:self cancelButtonTitle:@”Cancel”destructiveButtonTitle:@”Hello” otherButtonTitles:@”option 1″,@”option 2″,@”option 3″, nil];
desactionsht.actionSheetStyle=UIActionSheetStyleBlackTranslucent;
[desactionsht showInView:self.view];
NSLog(@”Destructive pressed –> Delete Something…”);
}
if ([buttonTitle isEqualToString:@”Other Button 1″])
{
NSLog(@”Other 1 pressed”);
}
if ([buttonTitle isEqualToString:@”Other Button 2″])
{
NSLog(@”Other 2 pressed”);
}
if ([buttonTitle isEqualToString:@”Other Button 3″])
{
NSLog(@”other 3 pressed”);
}
if ([buttonTitle isEqualToString:@”Cancel Button”])
{

UIAlertView *alrt=[[UIAlertView alloc]initWithTitle:@”Informative Alert” message:@”You pressed Cancel buttton” delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles:@”Okay..”, nil];
alrt.alertViewStyle=UIAlertViewStyleDefault;
[alrt show];
}
}

– (void)viewDidLoad
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(20.0f, 186.0f, 280.0f, 88.0f);
[button setTitle:@”Show ActionSheet” forState:UIControlStateNormal];
button.tintColor = [UIColor whiteColor];
[button addTarget:self action:@selector(showActionSheet:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.
}

– (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

Advertisements

2 thoughts on “UIActionSheet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s