我做了一個警告: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