I have an app with a UITabBarController and a few tabs, each of which contains a UINavigationController. I also have a UISearchController triggered by a search button on the nav bar, which has a custom search results view controller. Search works just fine, as does tapping cancel. I implemented presentSearchController: to present the search controller as a view controller using
[self presentViewController:animated:completion:];
, which also works fine.
Where I run into trouble is if the user dismisses the keyboard (search controller active), and then switches tabs on the tab bar, comes back to the original tab with search controller active, and then taps "Cancel", the underlying UINavigationController's view stack is gone from the main window hierarchy and doesn't get reloaded until I switch tabs and come back with search mode inactive.
This is similar to this issue: "From View Controller" disappears using UIViewControllerContextTransitioning
Except I don't use any custom transitions, and the tab bar still shows after tapping cancel. Printing the view stack shows the tab bar is the only subview of the window until I switch tabs again and everything displays as normal.
What is the best way to go about solving this? I really hate to brute force re-add the navigation controller's view to the window on didDismissSearchController:
as suggested. Not only does this seem like a bad idea, but I also run into issues with the z-ordering of the tab bar and the navigation controller when explicitly re-adding the nav controller to the key window.