UITabBarController - Jump from one navigation stack to view controller of another tab navigation stack

Beginner iOS developer. I am making a simple tabbed application in Swift using UITabBarController. For simplicity, let's assume that the application has only two tabs, Contacts and Chats. Each of the two tabs has a navigation controller.

The Chats navigation stack starts with a UITableViewController named ChatsTableViewController, which lists the user's chats. When the user selects a chat, the application navigates to the MessageViewController, which displays messages for the selected chat.

The Contacts navigation stack includes a UITableViewController that lists custom contacts. When a contact is selected, another view manager is presented modally, asking the user if they want to start a chat with the selected contact and give them the option to cancel. If the user chooses to start a chat, I would like to switch from this modal view controller to the MessageViewController of the Chats tab, passing in the information needed to display the chat (which I have out of the box in the modular view controller).

When the MessageViewController loads, whether we get it by selecting a chat from the Chats tab or creating a new chat from the Contacts tab, it should have a navigation bar at the top, Back, which takes the user to the ChatsTableViewController.

I searched a lot but couldn't find solutions that match what I need. Any suggestions would be appreciated! Here's a rundown of what I'm looking for.

  • The standard way to go from a view controller in one tab navigation stack to a view controller (which is not the root view controller in my case) of another stacked navigation stack is by passing the appropriate information to be displayed in the assign controller mode.
  • The controller transition I need to have a navigation bar with a back button that takes the user to the previous view controller in its navigation stack just as if they were accessing it from a normal tab navigation thread.

EDIT . I found that you can easily switch to tabs with self.tabBarController?.selectedIndex = index_of_tab_to_switch_to

, however this brings me to the first tab view and I'm still not sure how I can traverse the data. Any thoughts on how I can proceed?

+3


source to share





All Articles