views:

70

answers:

1

Hello, guys.

I have an app that if it is quit in a certain view, I want to restore this view exactly where the user left.

My applicationDidFinishLaunching is very simple at the moment:

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    // Override point for customization after app launch    
    [window addSubview:tabBarController.view];
 [window makeKeyAndVisible];

}

What can I do to restore a sequence of 3 view controllers that must be stacked in the tab bar controller?

Normally, the user do these interactions with the app to go in the view that I want to restore:

  1. App pops out;
  2. The first tab is a table view (so its the first view controller that I have to restore) and user selects a row;
  3. The view that appears is another table view (so its the second view controller that I have to restore) and user taps a + in the top bar of this view;
  4. The last view controller appears in a modal way (so its the third view controller that I have to restore).

I tried what the answer of this post suggests, but my tab bar controller turns out in a mess (the post don't use a tab bar controller and I'm a beginner in iPhone development, so my tries wasn't very successful).

Thanks in advance.

+1  A: 

It doesn't sound like you're describing typical UITabBarController use patterns, where you have a series of tabs that are always available and offer different modes of use for the application. Usually recreating the state of a tab bar controller is just a matter of instantiating the tabs as usual and selecting the current tab.

A sequence of screens that provide increasing levels of detail is the normal use pattern for UINavigationController.

You may want to investigate whether you have a sane design before worrying about how to restore it.

That said, you can either recreate your whole structure in applicationDidFinishLaunching, or you can give each class the logic to recreate the view controllers and views that are downstream. I would take the latter approach.

Seamus Campbell
Thanks, Seamus. The last approach that you mentioned is really better because separation of concerns. I will try it. In my app, just the first tab bar that has a table view that goes to another table view when user selects a row in the first one (a relation between activities and its executions). The other tab bars have other features too. Thanks a lot for your suggestion.
R31n4ld0_
Yep! Worked like a charm. In the viewDidLoad of each class I search for data in a plist file and recreate the stack with [controller1 presentModalViewController:controler2 animated:NO]. Thanks a lot.
R31n4ld0_