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

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];
}

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.

Related

tabbar with navigation controller iphone application

I have created a tabbar with navigation bar iphone application and i added another view which is coming from home tab.The view is coming but the navigation bar and tabbar are not coming.why?
Go in your application's delegate, find the method didFinishLaunchingWithOptions:.
Make sure you set the
self.window.rootViewController = self.tabBarController;
(where tabBarController is your tabbar controller - obviously).
Make sure you have the following line right before the end of the method:
[self.window makeKeyAndVisible];
Check your main .nib file (MainWindow.xib, probably) and make sure that at least the first TabBar item contains a navigation controller - which opens your view (the one you mentioned).
Hope you sort it out, good luck !

UINavigationController is overlapping a ModalViewController

I have an app which goes through a set of screens within a navigation controller, then there is a screen with a tab controller, which one of the contained views wants to display a modal view controller that should be displayed over the top of the whole app (not full screen though).
It's all working fine, but the modal window is partially covered at the top by the navigation controller. I've tried using self / self.tabBarController / self.navigationController / self.tabBarController.navigationController to call presentModalViewController but they either don't work or still display the modal window underneath.
I've been searching for an answer to this all day, everyone else seems to have problems when it DOES overlap, not when it doesn't.
Any ideas? Thanks. (code, screenshots & video below)
- (IBAction)add:(id)sender {
// create the view
AddAttainmentController *addScreen = [[AddAttainmentController alloc] init];
// pass in a selected pupil
[addScreen setPupils:[NSMutableArray arrayWithObject:pupil]];
// add the view to a navigation controller
UINavigationController *control = [[UINavigationController alloc] initWithRootViewController:addScreen];
// place the navigation controller on the screen
[self presentModalViewController:control animated:YES];
// release at the end
[control release];
[addScreen release];
}
Screenshots: http://cl.ly/032v2k0t0N1s1m3H0511 (you can see the navigation bar as the modal window slides in) http://cl.ly/1h0o453Y3Z051P3S1S37 (the navigation bar of the modal window is covered by the original)
Video: http://cl.ly/1e2J3o1q3V1l1j470m12
It sounds like you failed to consider some of the restrictions and assumptions around using Apple's view controller classes and are getting undefined and unexpected behavior as a result.
Tab bar controllers expect to always be at the root of your controller hierarchy. From the class reference:
When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller
Additionally modal view controllers (and all view controllers for that matter) are assumed to fill their window.

Trying to place a UINavigationController as one of the tabs inside a UITabBarController

I'm writing an iphone app that has 3 tabs. The first two are UITableViews, but the third tab i want to be a UINavigationController, because it is to be used for editing a list of recipes.
I've tried every combination of nibs i could think of to get this to work properly but am having problems such as:
once you click on the editing tab, then click back to the other tabs, the display still shows parts of the editing tab such as the navigation bar
when you click on the editing tab, you can see a blank navigation controller with no contents or title, even though my nav controller inside the tabs has the 'nib name' and the 'class' set in the inspector
I just would like to know the best way of going abouts doing this: putting an editor (which i think should be a navigation controller?) inside a tab. Is there something glaring i'm missing?
Thanks so much guys
I use to do editing buttons with navigation controller as well and it woks very well, so this is probably good option.
If you want navigation controller just for one view you need to hide it by switching tabs
self.navigationController.navigationBarHidden = YES; or NO
And since I don't use IB (it is black box) I would recommend you to allocate all (title, buttons, etc.) about navigation controller manually. Works great and you see what you've done.
OK i solved it. I was on the right track already anyway.
My main window now has a tab bar controller. One of the tabs has its nib name and class set to my view with navigation.
In my view with navigation, in the nib i have an empty view and a navigation controller. In the implementation file, i have the following code to attach the nav controller into the empty view, and it works nicely now!
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] addSubview:navController.view]; // This is the important line
}

Switching Views within UITabBar View

I have created an UITabView application. Each view selected from the bar is a seperate controller with own nib file. I switch between them succesfully.
In the first view I have two buttons (check out the screenshot). When clicking them I want to switch to another views which are the parts of the current view controller. I use:
[self presentModalViewController:anotherViewController animated:NO];
That switches the view, but hides the UITabBar. How to keep the bar on the screen after the switch?
P.S. Sorry for the blurred image. I am not allowed to share to much info.
Well I think you are misusing the modal view controller. For a problem like this I'll say you should put them in a view controller stack using UINavigationController. Instead of making each tab a UIViewController make it a UINavigationController, then you can push and pop view controllers on it, which still show the tab bar.
See http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
use: tabBarController.selectedViewController = newViewController
edit: UINavigationController is not needed here.

Tab Bar will no work as a subview of another view but works fine as a subview of window?

I am trying to make a program with three subviews after the title screen. Two of the views are just standard nib files with UIViewController subclassed to control them, and the third is a Tab Bar view. I can't seem to get the tab bar items to display though. I walked through the Tab bar chapter in "Beginning iPhone Development" which adds the Tab Bar Controller right off the bat as a subview of Window in the app delegate and that works fine. What I want to do though is load up my rootView controller after the third section was chosen from the title screen and then add a Tab Bar view to that. Every time I do this though I get a blank Tab Bar with no tab bar items.
Any help you can provide would be greatly appreciated seeing as I've been working at this for a few days now.
Thanks
You can't push a tab bar controller to a navigation controller, which I assume is what you're trying to do. However, you can use a plain UITabBar and implement your own view switching in a UIViewController subclass (rather than a UITabBarController). See this related question.