I have a tableview which, when loaded, each cell could possibly return an NSError, which I have chosen to display in a UIAlertController. Problem is I get this error in the
I found I needed to create a queue to stack the UIAlertController requests.
NSMutableArray *errorMessagesToShow; // in @interface
errorMessagesToShow=[[NSMutableArray alloc] init]; // in init
-(void)showError:(NSString *)theErrorMessage{
if(theErrorMessage.length>0){
[errorMessagesToShow addObject:theErrorMessage];
[self showError1];
}
}
-(void)showError1{
NSString *theErrorMessage;
if([errorMessagesToShow count]==0)return; // queue finished
UIViewController* parentController =[[UIApplication sharedApplication]keyWindow].rootViewController;
while( parentController.presentedViewController &&
parentController != parentController.presentedViewController ){
parentController = parentController.presentedViewController;
}
if([parentController isKindOfClass:[UIAlertController class]])return; // busy
// construct the alert using [errorMessagesToShow objectAtIndex:0]
// add to each UIAlertAction completionHandler [self showError1];
// then
[errorMessagesToShow removeObjectAtIndex:0];
[parentController presentViewController:alert animated:YES completion:nil];
}