Reputation: 54
How can I add an action to all of the "other" buttons?
This is how I am displaying the Alert:
- (IBAction)testCalAdd:(id)sender {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Select week"
message:@"Which week will you be attending?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"AIG Thermal $1 Million Grand Prix", @"DC VII", @"DC VI", @"DC V", @"DC IV", @"DC III", @"DC II", @"DC I", nil];
[alert show];
}
Upvotes: 0
Views: 128
Reputation: 5290
You can do this with a UIAlertViewDelegate
, but it's much easier to use PSAlertView.
Copied from another answer here.
PSAlertView *alert = [[PSAlertView alloc] initWithTitle:@"Contact"];
[alert setCancelButtonWithTitle:@"Dismiss" block:^{}];
[alert addButtonWithTitle:@"Call" block:^{
NSString *urlString = [NSString stringWithFormat:@"telprompt://%@", phoneNumber];
NSURL *url = [NSURL urlWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}];
[alert show];
Upvotes: 0
Reputation: 934
Check the delegate method:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
When you press any button in your alert, the index is showed in that method.
Upvotes: 2