0

I was wondering if you could help me. I am developing an app where I have five UIView Controllers, each with fields to be completed and filled in. At the bottom of the page I have created a bottom bar with five buttons, one for each controller.

What I want is the following: If a user has filled in half of lets say VC_1 and then goes to VC_2, fills in a few fields here, and then goes back to VC_1 or a new VC3, that the progress before is still there.

I have tried this using "presentViewController" on each button press, however what happens if I go back to 1 is that all fields are empty, probably because it throws the viewController on top of the current one. One way that the data is not deleted is if I use dismissViewController, however this always brings me back to VC_1 and would not work if I wanted to go back from VC_3 to VC2.

I hope my questions makes sense and that one of you could explain how I can achieve the above objective.

Cheers, Lennaert

lwm
  • 15
  • 5
  • have you looked at [UITabBarController](https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html)? – Allen Zeng Sep 16 '14 at 01:25

4 Answers4

2

Here are two idea which can help

  1. Create and use models that persist longer than any view controller.
  2. It sounds like you should use a UITabBarController.

For idea 1, whenever you are storing data create a class separate from any view controller to hold the data. When you create an instance your view controller, assign that data object to the view controller. Then when the view loads, use the data in the data object to fill in the fields. When the user makes a change with any of the controls, update the data object. See Model-View-Controller.

For idea 2, using a tab bar controller will keep active instances of all your view controller. That way you will not need to create new instances of them.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
1

Looks like UITabBarController is your friend. It manages showing and hiding of the views for you.

Allen Zeng
  • 2,635
  • 2
  • 20
  • 31
0

Instead of UITabBarController I think your best choice is a UIScrollView with big contentSize and pagingEnabled = YES. All in one viewController and you can customize the bottom bar as you like.

dopcn
  • 4,218
  • 3
  • 23
  • 32
0

Hmm Couple things to consider. As Per Allen's comment, you might want to consider embedding your project in a UITabBarController:

Here's how to do it programmatically:

@property (nonatomic, strong) UITabBarController *tabBarController;
     MyView * view = [[MyView alloc]initWithNibName:@"MyView" bundle:nil];

            view.title = @"My Planner";


          nav1 = [[UINavigationController alloc] initWithRootViewController:view];

              nav1.tabBarItem.image = [UIImage imageNamed:@"nofill_star.png"];

     self.tabBarController.viewControllers=[NSArray arrayWithObjects:nav1,nil];


OR 

   MyView * view = [[MyView alloc]initWithNibName:@"MyView" bundle:nil];

            view.title = @"My Planner";

self.tabBarController.viewControllers=[NSArray arrayWithObjects:view,nil];

Or from your story board, go to editor embed in tab bar. Also check out NSUserDefualts. That's something to consider as well.

user3124081
  • 412
  • 1
  • 4
  • 16