Testing my app, I noticed a button in my UI which presents a UIAlertController appeared to do nothing all of a sudden, after a few days.
So hooking up the console app I see UIKit spit out the following log when I press the button:
"Warning: Attempt to present UIAlertController on MyViewController which is already presenting SomeOtherViewController.
No view controller appears to be presented. SomeOtherViewController is not currently in the UI but for some reason after it was dismissed the presentedViewController property wasn't set to nil (haven't been able to reproduce the issue yet).
So SomeOtherViewController I know is a "Detail View Controller" which only get pushed on the UINavigationController stack (I never present it modally). The only time it gets presented modally is when it is a "preview view controller" used in UIContextMenuConfiguration, but otherwise it doesn't get presented. Has anyone run into this sort of situation before and know of a potential cause/solution?
The presentedViewController does not appear on screen but for some reason UIKit is holding a strong reference to it in the presentedViewController property which prevents subsequent calls to -presentViewController:animated:completion:
As a workaround I could try using the code below but I'd really like to find the root cause of the issue:
-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
UIViewController *currentPresentedVC = self.presentedViewController;
if ([currentPresentedVC isKindOfClass:[SomeOtherViewController class]])
{
//this is unexpected.
[currentPresentedVC dismissViewControllerAnimated:NO completion:^{
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}];
}
else
{
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}
}