Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I present multiple UIAlertController one after another?

Inside of a forin loop, I need to present an UIAlertController and wait for user confirmation before presenting the next one. I presented them inside a forin loop, but only the first one appears(after confirmation, the others don't show up).Any help would be greatly appreciated.

like image 547
iamarnold Avatar asked Oct 29 '25 20:10

iamarnold


1 Answers

You can use the UIAlertController delegate when a button is pressed you show the next alert.

Make a global alert index:

NSUInteger alertIndex = 0; 

Make a global NSArray with your alert details in a NSDictionary eg:

self.alerts = @[@{@"title":@"Alert", @"message":@"Message 1"}, @{@"title":@"Alert", @"message":@"Message 2"}];

Call your first alert with an index, eg:

...title:self.alerts[alertIndex][@"title"]...

and

...message:self.alerts[alertIndex][@"message"]...

In your alert controller delegate's didClickButtonAtIndex:

alertIndex++;
// call your next alert here, explained above.
like image 112
emotality Avatar answered Oct 31 '25 11:10

emotality



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!