【问题标题】:How to dismiss all the alertview from an array when select the cancel button in alertview?在alertview中选择取消按钮时如何从数组中关闭所有alertview?
【发布时间】:2016-04-26 06:03:45
【问题描述】:

在警报视图中选择取消按钮时如何从数组中关闭所有警报视图?我在一个数组中有 5 个警报视图。如果我从第一个警报视图中选择取消,那么它将需要关闭剩余的所有警报而不是显示。

for (NSDictionary *temp in [RMUserDefaults userDetails].SharedFolders)
    {
        NSString *name = temp[@"Name"];

        sharedFolderId = [RMUserDefaults userDetails].SharedFolders[0][@"id"];

        alert1= [[CustomUIAlertView alloc]initWithTitle:LString(@"RECEIPT_MATCH") message:[NSString stringWithFormat:@"%@ has SharedFolders you to a Team Plan.", name] delegate:self cancelButtonTitle:LString(@"CANCEL") otherButtonTitles:[NSMutableArray arrayWithObjects:LString(@"Upgrade Now"),nil]];
        alert1.tag = 12365;
        [alert1 show];
        double delayInSeconds = 5.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        });
    }

【问题讨论】:

    标签: ios objective-c iphone ipad alertview


    【解决方案1】:

    您可以使用以下代码关闭 UIAlertView。

    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    for (UIView *view in w.subviews) {
        if ([view isKindOfClass:[UIAlertView class]]) {
            [(UIAlertView *)view dismissWithClickedButtonIndex:[(UIAlertView *)view cancelButtonIndex] animated:YES];
        }
    }
    

    希望对你有帮助。

    【讨论】:

    • UIAlertView *topAlert = [NSClassFromString(@"_UIAlertManager") performSelector:@selector(topMostAlert)]
    • no 不行,我最近的项目尝试了各种方法,都行不通
    【解决方案2】:
     UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; 
            [alert1 show];
            [self performSelector:@selector(dismiss:) withObject:alert1 afterDelay:1.0];
    

    添加关闭方法

       -(void)dismiss:(UIAlertView*)alert
        {
            [alert dismissWithClickedButtonIndex:0 animated:YES];
        }
    

    【讨论】:

      【解决方案3】:
      UIWindow *Mywindow = [UIApplication sharedApplication].keyWindow;
      
      for (UIView *costumview in w.subviews) 
      {
          if ([view isKindOfClass:[UIAlertView class]])
          {
              [(UIAlertView *)view dismissWithClickedButtonIndex:[(UIAlertView *)view cancelButtonIndex] animated:YES];
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2016-01-12
        • 2012-09-03
        • 1970-01-01
        • 2016-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多