I have an iOS Objective-C application in which I am attempting to show a UIAlertController, from a UIViewController which is in the process of closing. I have tried adding this common workaround in AppDelegate
:
- (UIViewController *)currentTopViewController
{
UIViewController *topVC = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
while (topVC.presentedViewController)
{
topVC = topVC.presentedViewController;
}
return topVC;
}
Called with:
[appDelegate.currentTopViewController presentViewController:alert animated:YES completion:nil];
However this error is still appearing:
Warning: Attempt to present UIAlertController on MyViewController whose view is not in the window hierarchy!
Can anyone advise?