Hi
I've recently update my app to use AlertControllers
However when I present one within a Navigation Controller i'm getting this warning in the console:
"presenting view controllers on detached view controllers is discouraged"
I'm assuming this is because the alert controller isn't added to the navigation controller stack.
It doens't seem to be breaking anything but is there something else I should be doing to avoid the warning?
Thanks
Chris
What is "self" at the time you present the alertController which generates the warning? That is the view which is likely in the process of being presented or not in the current navigation stack.
If you want to track it down, I would start by setting breakpoints on these lines and examining the viewController referred to as "self" and its placement within the view hierarchy at that moment to gain an understanding of how your views are structured.
[self presentViewController:alertController animated:YES completion:nil];
If you want a simple solution that just makes the warning go away. then you can use something like the following to always present from a known view controller, although I would recommend looking into things a bit more. A good understanding of how views are organized and presented in an application will be helpful in the long run.
[self.view.window.rootViewController presentViewController:viewController animated:YES completion:nil];