UIAlertView无法正常运行

UIAlertView无法正常运行

本文介绍了UIAlertView无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试关闭UIAlertView时遇到问题. UIAlertView可以正确启动,并显示两个按钮:是"和否".但是,当我选择是"按钮时,什么也没有发生.我想知道自己在做错什么,为什么选择是"按钮时什么也没发生.

I have a problem when I try to dismiss my UIAlertView. The UIAlertView launches correctly, and displays two buttons: "Yes" and "No". However, when I select the Yes button, nothing happens. I am wondering what I am doing wrong, and why nothing occurs when the Yes button is selected.

我的代码如下:

-(IBAction)gotoURL
{

    [self displaySafariDialogue];

}

-(void)displaySafariDialogue
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Are you sure you wish to exit this app and launch the safari browser?"
                                                    message:@"Click yes to continue"
                                                   delegate:nil
                                          cancelButtonTitle:@"Yes"
                                          otherButtonTitles:@"No", nil];
    [alert setTag:100];
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    NSLog(@"Alert view button clicked");

    if(alertView.tag == 100)
    {

        if (buttonIndex==0)
        {
            NSLog(@"Yes button selected");
            NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

            if (![[UIApplication sharedApplication] openURL:url])
                NSLog(@"%@%@",@"Failed to open url:",[url description]);
        }
    }
}

推荐答案

您需要设置委托.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Are you sure you wish to exit this app and launch the safari browser?"
                                                message:@"Click yes to continue"
                                               delegate:self
                                      cancelButtonTitle:@"Yes"
                                      otherButtonTitles:@"No", nil];

这篇关于UIAlertView无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:38