提醒2个按钮 [英] Alert with 2 buttons

查看:110
本文介绍了提醒2个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在我的应用中找到一个指向网站的链接。用户将点击一个显示网站的按钮,一个警报将显示2个按钮。其中一个按钮就是取消按钮,另一个按钮将打开网站。

I'm going to have a link to a website in my app. The user will click on a button that says Website and an Alert will appear with 2 buttons. One of the buttons is just going to be a cancel button and the other button is going to open the website.

你能帮我解决这个问题吗?

Could you help me with this?

谢谢!

推荐答案

将此文件放入头文件中:

put this into your header file:

@interface YourViewController : UIViewController <UIAlertViewDelegate>

将此信息添加到课程中并附上提醒:

put this into the class with your alert:

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

这篇关于提醒2个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆