Reputation: 31
I'm quite new to Swift and was hoping someone would help me figure out a little something about Navigation.
I have a Tab Bar Controller with four tabs, each with its own Navigation Controller. I was wondering what is the best way to access a "common" view from any of those tabs without navigating to a different tab.
Think about the Twitter app: I can access the view that displays an user's profile info from the "Home" tab, from the "Search" tab or even from the "Notifications" tab, and when I click the back button, it will pop this "common" view controller from the current tab's navigation controller's stack and return to the current tab's previous view. Please correct me if I'm wrong.
Upvotes: 1
Views: 116
Reputation: 31
@JarWarren, I was indeed looking to do it in the storyboard, but I managed to do it programmatically, following Aaron's suggestion:
I created the ProfileViewController and didn't link it to any of the navigation controllers, then I assigned a value to its "Storyboard ID" property, so that I would be able to instantiate the view controller with storyboard.instantiateViewController.
guard let profileViewController = storyboard?.instantiateViewController(identifier: "ProfileViewController") as? ProfileViewController else {
fatalError("Unable to instantiate view controller with provided identifier.")
}
navigationController?.pushViewController(profileViewController, animated: true)
Thank you both for helping me out.
Upvotes: 1