2010-11-22 74 views
3

我将在我的应用程序中链接到网站。用户将点击一个表示网站的按钮,一个警报将出现2个按钮。其中一个按钮就是取消按钮,另一个按钮将打开网站。带2个按钮的警报

你能帮我解决吗?

谢谢!

+0

像lolcat下面说,请指定您正在使用的平台。特别是考虑到下面有两个完全不同但正确的答案。 – 2010-11-22 21:33:31

回答

6

要把它放到你的头文件:

@interface YourViewController : UIViewController <UIAlertViewDelegate> 

把这个入类的提醒:

- (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]; 
} 

添加这个方法:

- (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"]]; 
    } 
    } 
} 
+1

我假设你正在制作一个iPhone应用程序...根据你以前的发布历史记录。当你发布你的问题时,你应该指定这个 – Dima 2010-11-22 21:25:28