My app starts off with a Tab Bar Controller on the first screen after logging in:
Later on the user can tap to get back to that screen, by pressing the Home button. The code for that is:
self.present(self.mealPlanViewController, animated: true, completion: nil)
The issue is that when they go back to that view controller, the Tab Bar is no longer there.
How can I present the view controller with the Tab Bar again?
2
Answers
I was able to figure it out - please see below:
I added
@IBAction func unwindToContainerVC(segue: UIStoryboardSegue) {}
to the view controller I wanted to go back to. This added an Action Segue.I added the segue to the storyboard and gave it the identifier, "unwindToMealPlanViewController"
I added the following code to my Done button:
self.performSegue(withIdentifier: "unwindToMealPlanViewController", sender: nil)
These were some very helpful resources in solving this:
You said:
"Later on the user can tap to get back to that screen, by pressing the Home button. The code for that is:"
That is wrong. You are not "getting back" to anything. You are presenting
self.mealPlanViewController
modally. That means it is being drawn on top over everything else. Ifself.mealPlanViewController
was previously on-screen, bad things may happen.In order to help you sort it out, you need to explain your view controller hierarchy and the flow between screens. What is the name of your tab bar controller’s class? Of the view controllers that are displayed as tabs? How are you getting from the tab bar controller to the screen that contains the home button?