首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在safari中打开前的确认

在safari中打开前的确认
EN

Stack Overflow用户
提问于 2012-09-14 20:45:32
回答 3查看 728关注 0票数 1

我正在尝试添加一个UIAlertView来警告用户该链接将在Safari中打开。然后,用户可以选择OK(打开url)或cancel (取消),这应该只是关闭警报并返回到链接。我有三个不同的UIButton,其中有三个不同的URL

现在,ive为所有按钮添加了一个IBAction,并且所有按钮都有标签(我想我可以通过某种方式使用它:D)。我想- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:委托将很好地用于..

我的问题是:当用户单击ok时,UIAlertView如何知道要打开什么URL

EN

Stack Overflow用户

发布于 2012-09-14 22:23:51

解决方法如下:在创建UIAlertView时添加一个tag。如下所示:

代码语言:javascript
运行
复制
- (IBAction)PressedButton {

    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Link"
                                                      message:@"Want to open in safari?"
                                                     delegate:self
                                            cancelButtonTitle:@"Ok"
                                            otherButtonTitles:nil];

    message.tag = 2;        //different tag for each button

    [message addButtonWithTitle:@"Cancel"];
    [message show];

}

然后,当抛出- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex委托时,我这样做了:

代码语言:javascript
运行
复制
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if (buttonIndex == alertView.cancelButtonIndex){

        if (alertView.tag == 1)
        {
            //go to URL1
        }

        else if (alertView.tag == 2)
        {
             //go to URL2
        }

        else if (alertView.tag == 3)
        {
            //go to URL3
        }

    }
}
票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12424862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档