Normally, tab should retain its context.
h ttps://ux.stackexchange.com/questions/42197/ios-global-tab-bar-navigation-reset-navigation-stack-when-switching-between
I have tested on a simple app:
- initial view is a tabBarController
- In this, 3 tabs leading to FirstView, SecondView, ThirdView, each with simply a label to see where we are
- Then, I embed each of those in a NavController
- I add new views: FirstView2, SecondView2, ThirdView2
- In FirstView, add a next button to segue to FirstView2 with a show segue
- idem in SecondView and ThirdView
Then I tested:
- open app
Opens on FirstView
- click Tab 2
I see secondView
- click Tab 1: return to FirstView
Now to test state preservation
- Click next in FirstView
- shows FirstView2, with a back button at top and tabbar at bottom
- click Tab 2
I see secondView again
- click next: I see SecondView2
- click Tab 1: go to FirstView2
So, state was preserved
- click Tab 2: go to SecondView2
So, state was preserved
- click Tab 3: go to ThirdView
What is different in your setup ? How do you navigate from FirstView to FirstView2 ?
Normally, you have nothing to do more to retain the state.
If you cannot get it work, you may need to keep in a var the last view where you were in a tab.
And navigate to that view when you click tab again.
You will have to set a storyboard ID for each of the VC in navigation stack.
Have a look here to navigate programmatically.
https://stackoverflow.com/questions/39450124/swift-programmatically-navigate-to-another-view-controller-scene
But the best would first be to understand why it does nopt work as it should.