0
votes

I'm creating a Tab based application. One of the tab buttons displays a navigation controller when pressed. Which in turn displays the default root view controller associated with that navigation controller.

I want to allow the user to go backwards past the default controller that is displayed when clicking that tab bar button. Conceptually the "main" controller that is displayed when the user clicks the tab bar button would be the second controller in the navigation stack.

The reason I'm doing this is that the "back" controller is to be a kind of setting screen. Changing the setting would effectively make the "main" controller invalid and would need to be recreated. I know I could do settings screen as a modal view controller but when the modal controller is to be dismissed after the setting has been changed I would have to destroy the "main controller behind and rebuild it.

So my idea is to just pop the "main" controller off the stack to the settings screen and then once they have chosen the setting push a new instance of the "main" view controller onto the stack.

My two ideas were to implement this are:

  • Set the navigation controllers root controller to my "back" controller and push the "main" view controller on top. Then somehow override the tab bar button so that it always displays the second controller first, which exposes the back button in the navigation bar.
  • The other idea is to set the "main" view controller as the navigation controllers root , and then add a custom back button to the navigation bar which when clicked would somehow insert the "back" controller before the current one and then pop to it when clicked.

I've not been successfully with either of these approaches. I've seen over apps do this mainly Twitter apps where you can go back past the default controller that is loaded when clicking the tab bar item.

Anyone know how to do this? I would prefer to go down the tab bar button triggers the second controller in the navigation stack to be loaded by default.

1
is it necessary to rebuild the main controller or you can just make some modifications on it to apply the new settings ?Malek_Jundi

1 Answers

0
votes

If this is the apporoach you want to take, you could set yourself as the tabcontroller delegate and implement the method:

-tabBarController:didSelectViewController:

Here you can check if the selected controller is your navigation controller and then pop to the viewController you want.