0

第一个警报中的按钮执行第二个警报,这基本上是确认呼叫某人。我没有收到任何错误,但它不起作用。
当我按下第二个警报时,呼叫按钮崩溃了

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

     NSString *buttonString = [alertView buttonTitleAtIndex:buttonIndex];
     if ([buttonString isEqualToString:@"Phone"]) 
     {    
          UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Notice!" message:@"You are about to call .... Do you wish to continue?" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];    
          [alert2 show];

          if ([buttonString isEqualToString:@"Call"]){

              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://12345678"]]];

          }

          if([buttonString isEqualToString:@"Website"]){

              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"website"]];
          }

          if ([buttonString isEqualToString:@"Facebook"]){

             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/groups/..../"]];

          }
     }
}
4

4 回答 4

1

您在第二个警报视图中指定委托为 nil。这就是alertView:clickedButtonAtIndex:第二次不调用委托方法的原因。因此,您应该将委托分配为self.

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

                  NSString *buttonString = [alertView buttonTitleAtIndex:buttonIndex];

                  if([buttonString isEqualToString:@"Phone"]) {

                  UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Notice!" message:@"You are about to call .... Do you wish to continue?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];
                  [alert2 show];
                  }

                  if([buttonString isEqualToString:@"Call"]){

                     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://12345678"]]];
                  } 

                  if([buttonString isEqualToString:@"Website"]){

                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"website"]];
                  }


                  if([buttonString isEqualToString:@"Facebook"]){

                     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/groups/..../"]];
                  }

 }

我想这会对你有所帮助。

于 2012-07-30T12:13:04.363 回答
0

使用alertView:didDismissWithButtonIndex:委托方法而不是alertView:clickedButtonAtIndex:委托方法。警报消失后调用前者。当您想根据第一个警报视图的点击按钮显示第二个时,这更有意义。

还要给 UIAlertview 对象添加标签。

于 2013-12-09T05:59:17.607 回答
0

延迟启动第二个警报。问题是 - 警报需要一些时间来隐藏自己,然后才能出现任何新警报,因此直接调用第二个警报将不起作用。

试试这个,例如:

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

    NSString *buttonString = [alertView buttonTitleAtIndex:buttonIndex];
    if ([buttonString isEqualToString:@"Phone"]) 
    {
        [self performSelector:@selector(callSecondAlertView) withObject:nil afterDelay:1];
    }
}

- (void)callSecondAlertView
{
    //show new alert view
    UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Notice!" message:@"You are about to call .... Do you wish to continue?" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];

    [alert2 show];

    [alert2 release];
}

如果不工作,或延迟太久 - 玩afterDelay:价值。

于 2012-07-30T11:47:09.357 回答
0

知道了!出于某种原因,我第一个 alertView 按钮的 [[[alertView subviews] objectAtIndex:6] setBackgroundColor... 干扰了第二个 alertView 功能。在我将 xcode 更新到 4.4.1 之前,xcode 并没有直接引导我解决问题

于 2012-08-09T05:40:30.090 回答