ios - Build UIAlertController recursively and present it -


i want present uialertcontroller uialertcontrollerstyleactionsheet 1 after another. this, must present next uialertcontroller inside of handler of uialertaction.

uialertcontroller *a = [uialertcontroller alertcontrollerwithtitle:@"alert a" message:@"my alert a" preferredstyle:uialertcontrollerstyleactionsheet];  uialertaction* a_action = [uialertaction actionwithtitle:@"a action" style:uialertactionstyledefault handler:^(uialertaction * action) {     uialertcontroller *b = [uialertcontroller alertcontrollerwithtitle:@"alert b" message:@"my alert b" preferredstyle:uialertcontrollerstyleactionsheet];      uialertaction* b_action = [uialertaction actionwithtitle:@"b action" style:uialertactionstyledefault handler:^(uialertaction * action) {         uialertcontroller *c = [uialertcontroller alertcontrollerwithtitle:@"alert c" message:@"my alert c" preferredstyle:uialertcontrollerstyleactionsheet];          uialertaction* c_action = [uialertaction actionwithtitle:@"c action" style:uialertactionstyledefault handler:^(uialertaction * action) {             //keep going n number of uialertcontrollers want present         }];          [alert addaction:c_action];          [self presentviewcontroller:c animated:yes completion:nil];     }];      [alert addaction:b_action];      [self presentviewcontroller:b animated:yes completion:nil]; }];  [alert addaction:a_action]; [self presentviewcontroller:a animated:yes completion:nil]; 

is there way recursively?

you need 1 method shows 1 alert controller. in action handler call same method show next alert.

the trick knowing when stop , dealing each alert's message , buttons. following code assumes have instance variables contains way access messages , titles of each alert based on number. assume each alert has 1 button - 1 goes next alert.

something along lines of this:

- (void)shownextalert:(nsinteger)count {     nsstring *message = ... // determine message alert n     nsstring *title = ... // determine title alert n     nsstring *button = ... // determine title of action alert n      uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle:title message:message  preferredstyle:uialertcontrollerstyleactionsheet];      uialertaction *action = [uialertaction actionwithtitle:button style:uialertactionstyledefault handler:^(uialertaction *action) {         // process button alert n          // check see if alert should shown or not         if (count < self.maxalerts) {             // give current alert chance dismiss             dispatch_async(dispatch_get_main_queue(), ^(void){                 [self shownextalert:count + 1];             });         }     }];      [alert addaction:action];      [self presentviewcontroller:alert animated:yes completion:nil]; }  // elsewhere, show 1st alert [self shownextalert:0]; 

this code not tested should give general idea.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -