Search code examples
iosobjective-cswiftstoryboarduistoryboardsegue

Prevent removing overlayed controller from memory when switching tab in UITabView


I have a TabViewController. It contains a MapViewController with a NavigationItem (title bar with menu items). The MapViewController for itself modally shows another Controller (the settings) which also has a NavigationItem. My problem:

If the settings controller is shown and one switches to another tab and back (the settings controller is still open then) the underlying MapViewController is removed from memory so when the settings controller is dismissed, it shows a black screen where the map controller should be. How can I force to keep the map controller in memory?

  • All segues expect from modally "over current context" will cover the TabView, this should not happen, so it has to be a modal segue.

  • definesPresentationContext on the MapViewController preserves the map, yes. But when calling the settings controller it is embedded in the map view under the map view navigation item so there are 2 navigation bars. This obviously also mustn't happen.


Solution

  • The problem lies within the modal view. When switching back, the tabbar presented the settings controller but is unable to know from what it was modally called. Define the map view controller as current context and dismiss the navigation bar of the presenting view controller in the viewDidLoad of the upcoming settings controller. When using the setNavigationBarHidden(true, animated: true) it even has a nice look. The viewWillAppear is a nice place to get it back to place and keep the animations in sync.