我正在尝试添加一个UIAlertView来警告用户该链接将在Safari中打开。然后,用户可以选择OK(打开url)或cancel (取消),这应该只是关闭警报并返回到链接。我有三个不同的UIButton,其中有三个不同的URL。
现在,ive为所有按钮添加了一个IBAction,并且所有按钮都有标签(我想我可以通过某种方式使用它:D)。我想- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:委托将很好地用于..
我的问题是:当用户单击ok时,UIAlertView如何知道要打开什么URL?
发布于 2012-09-14 22:23:51
解决方法如下:在创建UIAlertView时添加一个tag。如下所示:
- (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委托时,我这样做了:
- (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
        }
    }
}https://stackoverflow.com/questions/12424862
复制相似问题