我怎样才能closuresUIAlertController没有button
我使用UIAlertController和UIActivityIndicatorView作为我的加载指示器,它将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]; }
- 足够! #AppStoreWalkout #iToo
- 通过Xcode bot创build的IPA无法为APNS运行,但是如果通过Xcode本身手动构build或通过Xcode构build为归档
- 将UIPanGestureRecognizer和UISwipeGestureRecognizer添加到相同视图会导致设置requireGestureToFail
- 点击一个button将文字放在图像上
- 限制(年龄保护)UIWebView,以避免17+用户评级
- 如何下载Cydia iOS 12.2、12.2.1、12.2.2、12.2.3
- 被调用两次的UICollectionView numberOfItemsInSection
- 将UISearchBar放在tableview上方,但不能放在tableview或navbar中
- 显示spiderfy leaflet注解MKMapView