ios - How can I close UIAlertController without button -


i use uialertcontroller , uiactivityindicatorview loading indicator, , close until app gets server response. when wrong server or network app never response, can't control alertview, want know there method can close alertview touching screen. , uialertview without title , buttons. hints thankful.

it crashed when touch screen, here 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]; 

save alert controller property (for example, alertcontroller) , close

[self.alertcontroller dismissviewcontrolleranimated:yes completion:nil]; 

to touching alert add tap gesture recognizer alertcontroller's view:

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

enter image description here


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -