NavigationController not displayed when used along with TabBarController - iphone

In my iphone app, i have a navigation Controller and a tabBar Controller.
The TabBarController has three tabs. In the second and third Tab the NavigationController are added to the viewControllers.
Problem :
In third tab viewController shows the NavigationBar but the in second tab viewController doesnot display navigationBar.
Things I have tried and checked:
1) I checked that all the connections in IB are done properly
2) I checked the size of frame for the view. It doesnot overlap the navigationBar.
3) I also tried using self.navigationController.navigationBar.hidden = NO;
But still it does not show the navigationBar in the second tab.
What should I do?
Please Suggest
Please Help
Thanks!!

We can't do much without looking at your code.
Assuming your TabBarController is properly connected in Interface Builder, you'll need something similar to this:
UIViewController *firstView = [[UIViewController alloc] init];
UIViewController *secondView = [[UIViewController alloc] init];
UIViewController *thirdView = [[UIViewController alloc] init];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:secondView];
UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:thirdView];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstView, firstNav, secondNav, nil];
Of course, have every view released afterwards.

Hmmm thats a problem i faced too.
If you look at your IB file ,you'll see that you can do a bit of tweaking and acheive it.
i'll post details as soon as i get time.

Oops!!! a big mistake on my part.I did not check the checkbox for "show navigation bar" in inspector for NavigationController. Hope this helps someone.

Related

Setting image on tabbar items in special case(if tab bar taken on viewController)

I am taking tab bar controller on view controller rather than delegate, and used code what mentioned below.
tabController = [[UITabBarController alloc]init];
tabController.delegate = self;
scanView = [[ScanTicketView alloc] init];
searchView = [[SearchView alloc] init];
historyView = [[HistoryView alloc]init];
tabController.viewControllers=[NSArray arrayWithObjects:scanView,searchView,historyView, nil];
[self.navigationController pushViewController:tabController animated:YES];
It works, but now how to apply images to these views. Can anyone help me here.
Thanks in advance.
You can use:
viewController.tabBarItem.image = [UIImage imageNamed:#"imageName.png"];
if you want to apply the image only to selected view controller in Tab bar, then UITabBarController has a selectedViewController and a selectedIndex property also see tabBarController.tabBar.selectedItem.tag if this may help.
Tabbar controller has its own property of Image and Title.
Go through this UITabbar Tutorial to understand properly. You can set image through property window or even through coding also.
Best Luck !

Single tab in UITabBar does not contain a UINavigationBar

I'm having a really strange issue. I've written an app with five tabs in a UITabBar. When I set the TabBarController's viewControllers property, I set it with five UINavigationControllers, so that each tab will have a UINavigationController within it.
Four of the tabs have it working perfectly. The navigation bar is there when I launch and switch to that tab. However, one of the tabs does not contain the UINavigationBar as I expected it to, and I can't understand why, because I initialized it exactly the same way I initialized all the others.
Here's some sample code from the AppDelegate.m file of initializing the individual view controllers:
SpotFilterViewController *spotList = [[SpotFilterViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:spotList];
[tabs addObject:navigationController];
[navigationController release];
[spotList release];
MySpotViewController *mySpot = [[MySpotViewController alloc] initWithSpot:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:mySpot];
[tabs addObject:mySpot];
[navigationController release];
[mySpot release];
Note: navigationController was declared above.
Anyone else run into this problem before? Or anyone have any idea why this might be happening? Any help is much appreciated. Thanks!
The problem is that you are doing this:
[tabs addObject:mySpot];
instead of this:
[tabs addObject:navigationController];

UINavigation Controller and UITabbarController connumdrum

I have searched and searched but as yet still cannot figure this ole problem out! :-(
I have in my main.xib a TabBarController that is setup with five viewControllers.
I am trying to get the first viewcontroller to be a nav controller so that if the first tab is selected I can push and pop views into view.
But for the life of me I cannot get this to work?
I tried this in my app delegate didLaunch method:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
FirstViewController *first = [[FirstViewController alloc] initWithNibName:#"FirstView" bundle:[NSBundle mainBundle]];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:first];
NSArray* controllers = [NSArray arrayWithObjects:firstNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
for which I see my view displayed but no buttons appear on the tab bar?
Any tip please?? thnx
For that, you have to add View Controllers in TabBar programatically. Like below:
oFirstViewController.title = #"First View";
oFirstViewController.tabBarItem.image = [UIImage imageNamed:#"ico.png"];
UINavigationController *myNavigationController1 = [[UINavigationController alloc] initWithRootViewController:oFirstViewController];
tabBarController.viewControllers = [NSArray arrayWithObjects:myNavigationController1, myNavigationController2, myNavigationController3, myNavigationController4, nil];
This way, you have to add remaining view-controller to your tabbar controller.
Hope it will he helpful to you.
Let me know in case of any difficulty.
Your tabBarController contains only one viewController. So there will be only one tabBarItem available in tabBarController. As there is only one viewController available, that tabBarItem will be selected by default and you can't change the selection. So you don't feel like there is a button. But its there. You can set the title and image for the viewController and you will see the difference.
first.title = #"firstTab";
first.navigationItem.image = [UIImage imageNamed:#"firstTab.png"];
Below is the link that explain how to setup tabbar controller and navigation controller
Link 1
Hope it helps you......
[first.tabBarItem initWithTitle:#"First" image:[UIImage imageNamed:#"first.png"] tag:0];

MoreNavigationController images disappearing on select

I have a UITabBarController which has been created programatically, which has 6 tabs. As such the MoreNavigationController is automatically created to take care of having more than 5 tabs. Everything looks fine when the MoreNavigationController is displayed, but when I select one of these rows to push the view controller on to the stack, the cell image (tab bar image) disappears. When I pop that view controller, the image remains hidden until the pop animation is completed, at which point the image suddenly appears again.
This is fairly old code and I wouldn't do it this way these days, but everything works except for this last little thing so I'm pretty hesitant to rip out all the code and do it another way. Can anyone suggest what I might be doing wrong?
An example of creating one of the tab bar view controllers:
InfoViewController* infoViewController = [[InfoViewController alloc] init];
infoViewController.tabBarItem.image = [UIImage imageNamed:#"90-life-buoy.png"];
infoViewController.tabBarItem.title = #"More Info";
infoViewController.title = #"More Info";
UINavigationController* infoNavController = [[UINavigationController alloc] initWithRootViewController:infoViewController];
[infoViewController release];
Creating the tab bar:
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:outdoorsNavController, peopleNavController, citiesNavController, landscapesNavController, infoNavController, basicsNavController, nil];
[window addSubview:tabBarController.view];
EDIT: Doesn't seem to make any difference whether I use retina (#2x) images or not.
The issue is because you're wrapping your InfoViewController in a UINavigationController.
When you click on the table row in MoreNavigationController, the controller uses the tabBarItem in UINavigationController while it does its transition. Because this is nil (in your code), the image in MoreNavigationController disappears. When the transition finally finishes, MoreNavigationController picks up the tabBarItem in InfoViewController
Try this:
InfoViewController* infoViewController = [[InfoViewController alloc] init];
infoViewController.tabBarItem.image = [UIImage imageNamed:#"90-life-buoy.png"];
infoViewController.tabBarItem.title = #"More Info";
infoViewController.title = #"More Info";
UINavigationController* infoNavController = [[UINavigationController alloc] initWithRootViewController:infoViewController];
//Set the tabBarItem for UINavigationController
infoNavController.tabBarItem = infoViewController.tabBarItem
[infoViewController release];
Here's a video reproducing and fixing the issue:
Item 7 has an empty tabBarItem.image while Item 6 has tabBarItem.image set
I'm not sure, but have you tried setting the NavigationCotroller's .tabBarItem?
Not sure if I understand correctly, but on the top of my head here are some suggestions (The More Tab Bar item shouldn't disappear at all times, that is created automatically)
Have you tried subclassing your UINavigationController that is being used for the MoreController's place and set its tab bar items properties there, therefore making sure you have control over its lifetime ?
Subclass your UIViewController's that you wish to push onto the navigation stack and have them use the same tab bar item ?
Mimic the default functionality, create your own UITableViewController to act as the More Controller, and at each tap of the rows, do what you want, also in a custom way.
PS: Try setting images name without the .png extension. This way you will automatically load the #2x resource as well. Eg: [UIImage imageNamed:#"90-life-buoy"]
Link

How do I add a UINavigationController to a view in code?

view1 = [[View1 alloc] init]; //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];
View1 is inherit from UIViewController. So I create a *view1, then I create a UINavigationController, call *navigationController1. How do I link the two together? Thank you very much
The way to link a view controller with a navigation controller is to push the view controller onto the navigation stack. For example:
UIViewController * yourViewController = [[UIViewController alloc] init];
UINavigationController * navigation = [[UINavigationController alloc] init];
[navigation pushViewController:yourViewController animated:NO];
[yourViewController release]
Finally release the view controller at the end since the navigation controller retains it.
You may have things a little mixed up. A UINavigationController is generally attached to a UIViewController, which itself is what contains the UIView.
Before writing your own code, you might take a look at the navigation controller sample application project that is available from Xcode's new project template list, to figure out how it works.
The answer for this question is here: Having problem with pushViewController!! Help