我做了一个警告:AlertView打开Safari
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];
正如你所看到的,我的第二个按钮被称为 “野生动物园”,它是通过这个代码授权:
-(void) alertView: (UIAlertView *)alert1: clickedButtonAtIndex:(NSInteger)buttonIndex{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]];
}
但是现在,如果我点击确定(取消按钮),它会打开safari,如果我点击Safari,它也会打开safari。 如果我写:
-(void) alertView: (UIAlertView *)otherButtonTitles Safari: clickedButtonAtIndex:(NSInteger)buttonIndex{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://google.com"]];
}
两个按钮取消。 我该如何解决这个问题?其目的是按“OK”抵消,而“野生动物园”,以打开Safari
不,它不工作: – Alessandro 2012-02-18 18:21:16
- (空)alertView:(UIAlertView中*)报警1:clickedButtonAtIndex:(NSInteger的)buttonIndex { 如果(buttonIndex == 0) NSLog(@“@ Cancel”); { NSLog(@“@ Cancel”); } else { NSLog(@“Safari”); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@“http://google.com”]]; } } – Alessandro 2012-02-18 18:22:00
抱歉没有意识到委托函数签名是错误的!现在检查结果。 – cocoakomali 2012-02-18 18:26:43