i have made an alert:
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"mymaths.co.uk" message:@"This is a great website for maths exercises!! Have fun!!\n\rIf you prefer to view the website in Safari just press \"Safari\"" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: @"Safari",nil];
[alert1 show];
As you can see, my second button is called “Safari”, and it is delegated through this code:
-(void) alertView: (UIAlertView *)alert1: clickedButtonAtIndex:(NSInteger)buttonIndex{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]];
}
But now if I click Ok (the cancel button) it opens safari, and if I click Safari, it opens safari as well.
if I write:
-(void) alertView: (UIAlertView *)otherButtonTitles Safari: clickedButtonAtIndex:(NSInteger)buttonIndex{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]];
}
both buttons cancel.
How can I fix this? the aim is to press “OK” that cancels, and “Safari” to open safari
Handle the alert view delegates with button indexes in the below function that will do,