So in my Xamarin.iOS project, I have an abstract view class (let's call it A) with code that looks like this:
PresentViewController(_alertController, false, null);
where:
_alertController = UIAlertController.Create(message, null, UIAlertControllerStyle.Alert);
This is supposed to surface a "Loading..." alert, that should only disappear once the service call that is tied to the action taken returns. At this point, the alert should be dismissed with the code:
_alertController.DismissViewController(false, null);
However, I noticed that this code doesn't always work. In particular, there are instances in which the service call gets back and the program tries to dismiss the alertController before it is even presented and added to the parent viewcontroller.
There are some child classes of A for which this problem never happens, and one child class (let's call it C, where C: A) in which we almost always run into this problem. I don't know if the problem is related to different class behaviors, but just figured I'd provide this information in case useful.
I've also noticed that in the instances where the problem doesn't occur in view class C, the view has the following fields (which are null when the problem occurs):
ChildViewControllers {UIKit.UIViewController[1]}
ModalViewController {UIKit.UIAlertController}
NavigationController {UIKit.UINavigationController}
PresentedViewController {UIKit.UIAlertController}
PresentingViewController {UIKit.UINavigationController}
I would really appreciate any ideas for how I can address the issue. I apologize if the solution is obvious - I'm very new to iOS development and have been staring at the problem for too long, so I'm low on ideas.
Thank you