UIAlertView没有打电话

时间:2014-11-03 01:52:57

标签: ios uialertview

我正在尝试创建一个简单的网页浏览器式应用程序,无论何时用户想要使用后退,本地或转发功能,都会通过警报视图来确认。

控制台窗口确认调用IBAction没有问题,但每当我希望它调用Alert View时就会出现空白。

任何帮助都将不胜感激。

- (IBAction)controlPanelActions:(id)sender{
if (_controlPanel.selectedSegmentIndex == 0)
{
    if ([_viewWeb canGoBack])
    {
        [self askToGoHome:nil];
    }

}



- (IBAction)askToGoHome:(id)sender {
UIAlertView *alertDialog;
alertDialog.tag = 2;
alertDialog = [[UIAlertView alloc]

               initWithTitle: @"Confirm"
               message:@"Continue with Home Action?"
               delegate: self
               cancelButtonTitle: @"Yes"
               otherButtonTitles: @"No", nil];

[alertDialog show];
}





- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];

if (alertView.tag == 1)
{
    if ([buttonTitle isEqualToString:@"Yes"])
    {
        NSLog(@"back - yes");
        [_viewWeb goBack];
    }
}

 if (alertView.tag == 2)
 {
     NSLog(@"home - pre-yes");
     if ([buttonTitle isEqualToString:@"Yes"])
     {
         NSLog(@"home - yes");
          HOMEPAGEURL = [[NSURL alloc] initWithString:HOMEPAGE];
         [self.viewWeb loadRequest:[NSURLRequest requestWithURL:HOMEPAGEURL]];
     }
 }
if (alertView.tag == 3)
{
    if ([buttonTitle isEqualToString:@"Yes"])
    {
        [_viewWeb goForward];
    }
}
}

2 个答案:

答案 0 :(得分:1)

在调用init之前设置alertDialog.tag = 2;

因此,每次设置标记时,都会将标记设置为nil。它将无效。

答案 1 :(得分:0)

Alertview alloc和init方法将其标记设置为0。

所以alertDialog.tag = 2;

无效。

在alloc和init方法之后添加此行。

相关问题