How can I use two actions for UIButton
click?I have a UIAlertView showing with two button.Play again and exit.Now i want to execute two method in the click event of these buttons.
-
Please create a bit more context, your question contains the word UIAlertView and the description doesn't hint how that fits in.– Nick WeaverApr 23, 2011 at 10:10
-
i have updated the question.please check it now.and tell me how can i do this?– sohel14_cse_juApr 23, 2011 at 10:14
-
i couldn't solve the problem yes...can you help me?– sohel14_cse_juApr 23, 2011 at 11:52
Add a comment
|
1 Answer
UPDATE - May 2016
UIAlertView is deprecated. You can now use UIAlertController as explained here.
Old Answer with UIAlertView
You can create a UIAlertView like this
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Really reset?" message:@"Do you really want to reset this game?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"reset", nil]; [alert show];
To handle AlertView button click, you have to conform to
UIAlertViewDelegate
protocol.@interface YourViewController:UIViewController<UIAlertViewDelegate>{ ....... ....... }
Then implement
UIAlertViewDelegate
protocol methods,- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == [alertView cancelButtonIndex]){ //cancel clicked ...do your action }else{ //reset clicked } }
-
1where should i put this funciton : - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { //cancel clicked ...do your action } else if (buttonIndex == 1) { //reset clicked } } Apr 23, 2011 at 10:20
-
1
-
oops yes..do one thing too, in the .h file of your controller confirm to UIAlertViewProtocol, ie if your controller name is SomeController in the .h file when we declare @interface SomeController:UIViewController<UIAlertViewDelegate> Apr 23, 2011 at 10:21
-
my .h file starting like this already : how can i use another delegate here?@interface GameTableView : UITableViewController Apr 23, 2011 at 10:39
-
11