iphone tab app architecture question

181 views Asked by At

I have two tabs on my app that handle different flows.

For each tab I want to have a controller that determines (based on info in the app) which view to display.

So you click on tab 1, the app goes through some logic and displays either View B or View C. From there I use a navigation controller to go to other views within that tab.

To handle the initial logic of figuring out which view (B or C) to display I have a view controller (View A) linked to the tab that handles all the logic. My issue is that if I click on tab 1 while I'm already "on" the tab it displays the view for View A, which is a blank page.

Does anyone have an idea of how to architect this or make it so the view for View A is never displayed?

2

There are 2 answers

1
amattn On BEST ANSWER

UITabBarControllerDelegate

in your implementation of:

tabBarController:shouldSelectViewController:

you should try to detect if you are already on the first tab or not. if so just return NO and it won't pop to the root controller (in this case A)

1
anthonyvd On

The idea behind the MVC model is that such logic is not execute by ViewControllers but by the Model.

You could create a class or method who's purpose is to make the decision between view B or C, call the appropriate method on a button click and display the view depending on the result.

My point is: the way you describe it view A should not exist.