This tutorial is use to show the use of the Action Script .


1.  Open the xcode & choose "File->New Project".

2.  Select "View Based Application" from left menu .

3.  Name your project as "ActionSheet" and save the project.

4.  Then  select "ActionSheetViewController.h" file from the left side menu or group and files. Then enter the following :

#import <UIKit/UIKit.h>


@interface ActionSheetViewController : UIViewController<UIActionSheetDelegate> {


IBOutlet UILabel *label;

}



@property (nonatomic,retain) UILabel *label;

-(IBAction)showActionSheet:(id)sender;


@end


 

5. Then  select "ActionSheetViewController.m" file from the left side menu or group and files.

#import "ActionSheetViewController.h"


@implementation ActionSheetViewController

@synthesize label;



-(IBAction)showActionSheet:(id)sender {

    UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Action Sheet" delegate:selfcancelButtonTitle:@"Cancel Button" destructiveButtonTitle:@"Destructive Button"otherButtonTitles:@"Other Button 1", nil];

    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;

    [popupQuery showInView:self.view];

    [popupQuery release];

}

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

if (buttonIndex == 0) {

        self.label.text = @"Destructive Button";

    } else if (buttonIndex == 1) {

        self.label.text = @"Other Button 1 Clicked";

    } else if (buttonIndex == 2) {

        self.label.text = @"Other Button 2 Clicked";

    } else if (buttonIndex == 3) {

        self.label.text = @"Cancel Button Clicked";

    }

}

- (void)didReceiveMemoryWarning {

// Releases the view if it doesn't have a superview.

    [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.

}


- (void)viewDidUnload {

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}



- (void)dealloc {

    [super dealloc];

}


@end


 
6.  Then Open the "ActionSheetViewController.xib" from the resources package and then drag  button and label on the window view. Then make a connection among IBoutlet variable and there view and to IBAction method.

 

7. Click on the built and run tool , then save it and you will have the output screen in front of you. Click on the particular button to get the label name associated with that button on the label display.

[iPhone Development] [iOS Development] [iPhone Control] [iPhone Tutorials] [iOS Tutorials]