我将在我的应用程序中添加一个指向网站的链接。用户将单击一个显示“网站”的按钮,然后将出现一个带有 2 个按钮的警报。其中一个按钮只是取消按钮,另一个按钮将打开网站。
你能帮我解决这个问题吗?
Thanks!
将其放入您的头文件中:
@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"]];
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)