首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AlertView内部的alertView

AlertView内部的alertView
EN

Stack Overflow用户
提问于 2012-07-30 19:40:22
回答 4查看 632关注 0票数 0

第一个警报中的一个按钮执行第二个警报,这基本上是对呼叫某人的确认。我没有得到任何错误,但它不工作。

当我按下第二个警报时,呼叫按钮就会崩溃

代码语言:javascript
复制
-(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/..../"]];

          }
     }
}
EN

回答 4

Stack Overflow用户

发布于 2012-07-30 20:13:04

您在第二个警报视图中将委派分配为nil。这就是第二次不调用alertView:clickedButtonAtIndex:委托方法的原因。所以你应该将委托赋值为self

代码语言:javascript
复制
    -(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/..../"]];
                  }

 }

我想这对你会有帮助的。

票数 1
EN

Stack Overflow用户

发布于 2012-07-30 19:47:09

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

例如,请尝试执行以下操作:

代码语言:javascript
复制
- (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:值播放。

票数 0
EN

Stack Overflow用户

发布于 2012-08-09 13:40:30

明白了!由于某种原因,[[alertView subviews objectAtIndex:6] setBackgroundColor...对于第一个alertView按钮,我有干扰第二个alertView功能。但是,直到我将xcode更新到4.4.1之后,xcode才直接指向这个问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11720795

复制
相关文章

相似问题

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