我怎样才能closuresUIAlertController没有button

我使用UIAlertController和UIActivityIndi​​catorView作为我的加载指示器,它将closures直到我的应用程序获得服务器响应。 但是当我的服务器或networking出现问题时,我的应用程序永远不会得到响应,我无法从AlertView取回我的控制权,我想知道是否有一些方法可以通过触摸屏幕closures此AlertView。 而我的UIAlertView是没有标题和任何button。 任何提示将是感恩。

当我触摸屏幕时它崩溃了,下面是我的代码:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"正在装载页面...\n\n" preferredStyle:UIAlertControllerStyleAlert]; UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; spinner.center = CGPointMake(130.5, 65.6); spinner.color = [UIColor darkGrayColor]; [spinner startAnimating]; [alert.view addSubview:spinner]; UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc]initWithTarget:alert action:@selector(stopWaiting)]; [alert.view addGestureRecognizer:recognizer]; 

将警报控制器保存到某个属性(例如, alertController )并closures它

 [self.alertController dismissViewControllerAnimated:YES completion:nil]; 

要触摸警报,请在alertController的视图中添加轻击手势识别器:

 - (void)showAlert { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"Some message" preferredStyle:UIAlertControllerStyleAlert]; UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeAlert)]; [alertController.view addGestureRecognizer:tapGestureRecognizer]; self.alertController = alertController; [self presentViewController:alertController animated:YES completion:nil]; } - (void)closeAlert { [self.alertController dismissViewControllerAnimated:YES completion:nil]; } 

在这里输入图像说明