Search code examples
iphonetabbarcontrolleriphonecoredatarecipes

Looking for tutorials on iPhoneCoreDataRecipes App


I am finding it very difficult to grasp how the Views are loaded and wired with the TabBarController in the iPhoneCoreDataRecipes App.

Does anyone have any pointers on how to learn the concepts presented in this Apple sample App? I have read the other items on Apple developer site.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
   recipeListController.managedObjectContext = self.managedObjectContext;
   [window addSubview:tabBarController.view];
   [window makeKeyAndVisible];
}

My understanding of the above
Line 2: Populating the list controller?
Line 3: Adding a Sub view to the tab controller view?

If my understanding of line 3 is correct, where are the other views, Unit Conversion, added to the tabcontroller?


Solution

  • A tab bar controller requires a list of view controllers. I haven't seen this specific sample, so it may be taken care of by the first line. However, normally you would do the following:

    1. Instantiate all view controllers:

      UIViewcontroller *viewControllerTab1 = ...
      UIViewcontroller *viewControllerTab2 = ...
      UIViewcontroller *viewControllerTab3 = ...
      
    2. Add them to the tab bar controller:

      tabBarController.viewControllers = 
        [NSArray arrayWithObjects:
           viewControllerTab1,
           viewControllerTab2,
           viewControllerTab3, 
           nil
        ];
      
    3. Then you would add the tabBarController's view to the window as a subview, followed by window makeKeyAndVisible (lines 2 and 3). These are not specific to the tab bar, they just add the tab bar view to the main application view, like you would any other view controller.

    You may also either specify the UITabBarItem details here, or on the view Controllers. You should do it here so that you don't run into any problems with the tab bar items not showing up. I.E.

    viewControllerTab1.tabBarItem = [UITabBarItem init...]