Do anyone know how to make actions for the buttons in UIAlertview
? if so, please guide me.
Asked
Active
Viewed 9,672 times
3

Jhaliya - Praveen Sharma
- 31,697
- 9
- 72
- 76

adhees
- 79
- 2
- 5
5 Answers
4
When buttons are clicked in UIAlertView, its delegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
gets called. Your delegate must implement this method and check which button was pressed.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:
// Do something for button #1
break;
case 1:
// Do something for button #2
break;
...
}
}
If you have multiple alert views, then you can differentiate them by their title as follows:
if ([alertView.title isEqualToString: yourAlertView.title]) {
// proceed...
}
-
@Malloc use %i buttonIndex is an int not a double. – Albert Renshaw Jul 17 '14 at 21:14
2
Read the below article , will help you to understand the UIAlertViewDelegate
.

Jhaliya - Praveen Sharma
- 31,697
- 9
- 72
- 76
2
Please use this code
First Set delegate for UIAlertView then write its delegate method as follows...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
//Some Implementation
} else if(buttonIndex == 1) {
//Some Implementation
}
}

Mehul Mistri
- 15,037
- 14
- 70
- 94
1
If you want to get action for UIAlerView button.
You need to use UIAlertViewDelegate and its method for get action.
For Reference,

Chetan Bhalara
- 10,326
- 6
- 32
- 51