How are the 2 View Controllers wired to the tabBarController in iPhoneRecipes

扶醉桌前 提交于 2019-12-11 16:59:32

问题


I am learning iPhone programming by reviewing the iPhone Recipes sample application.

I am puzzled with how the two view controllers are wired to the tab bar. If they are wired in the XIB, can anyone explain how it is done or where I can get more visually aided details on connecting things in the XIBs.

This is my starting point in the learning process:

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

回答1:


Basically, the view property of the tab bar is being added as a subview of the window.

The view property of the tab bar points at the tab bar's visual component, (the tab bar view itself) and the tab bar controller handles its behaviour (changing tabs, etc).

Each individual tab is a subview of the tab bar, so when the tab bar view is added as a subview of the window, its subviews are brought along for the ride. It's a little tricky to get your head around at first, but it should start sinking in after youplay around with interface builder a bit more.

All that's happening in the XIB is you're setting the view outlets on each tab so that they can be displayed when each tab is selected.

Hope this helps.



来源:https://stackoverflow.com/questions/1029122/how-are-the-2-view-controllers-wired-to-the-tabbarcontroller-in-iphonerecipes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!