Search This Blog

Thursday, 23 August 2012

How to use UIActionSheet in xcode

Hello Friends,
                     Today, i am giving you something good to prevent your user doing things accidentally - the answer is UIActionSheet ,a very good option to ask user if he is sure or anything.
Follow the code :

Code:

Suppose you have a viewController,in viewController.h file do something like this we are including UIActionSheetDelegate here like implementing interfaces in java :

@interface Home:UIViewController<UIActionSheetDelegate>

.....
.......
........
.....
-(IBAction)buttonClicked:(id)sender;

@end


Now,Suppose you have a button and you want to ask your user if he/she is sure? Do something like this on your viewController.m file:

-(IBAction)buttonClicked:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle: @"Are You Sure?" delegate:self cancelButtonTitle:@"NO" destructiveButtonTitle:@"YES" otherButtonTitles:nil,nil];

[actionSheet showInView:self.view];

}

Now you are supposed to override a function that is :

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

if(!buttonIndex==[actionSheet cancelButtonIndex]){
//do something on click of 'YES'.

}

}




ask for any queries

No comments:

Post a Comment