Comment puis-je fermer UIAlertController sans button

J'utilise UIAlertController et UIActivityIndicatorView comme indicateur de chargement, et il se ferme jusqu'à ce que mon application obtienne la réponse du server. Mais quand quelque chose ne va pas avec mon server ou mon réseau, mon application ne recevra jamais de réponse, je ne peux pas récupérer mon contrôle de l'AlertView, je veux savoir s'il existe une méthode qui peut fermer cette AlertView en touchant l'écran. Et mon UIAlertView est sans titre et aucun button. Tous les indices seront reconnaissants.

Il s'est écrasé quand j'ai touché l'écran, voici mon code:

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]; 

Enregistrez votre controller d'alerte sur une propriété (par exemple, alertController ) et fermez-le avec

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

Pour le faire en appuyant sur l'alerte, ajoutez un outil de reconnaissance gestuelle à la vue 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]; } 

entrez la description de l'image ici