Placez ceci dans votre fichier d'en-tête:
@interface YourViewController : UIViewController <UIAlertViewDelegate>
tout mettre dans la classe avec votre alerte:
- (void)alertOKCancelAction {
// open a alert with an OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Open?" message:@"Open Website?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Open", nil];
alert.tag = 1;
[alert show];
[alert release];
}
ajouter cette méthode:
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if(alert.tag == 1)
{
if(buttonIndex == alert.cancelButtonIndex)
{
NSLog(@"cancel");
}
else
{
NSLog(@"ok");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://www.google.com"]];
}
}
}
Comme lolcat dit ci-dessous, s'il vous plaît spécifier quelle plate-forme vous travaillez. Surtout en considérant qu'il y a deux réponses complètement différentes, mais correctes, ci-dessous. –