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];
Related
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];
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.
Scenario: UITabBarController has three tabs corresponding to each of three view controllers which are successfully instantiated / initialized.
On launch, the second tab is selected automatically, and one can toggle back and forth between the second and third tabs.
The first tab, however, does not respond to taps. One cannot switch to the first tab.
All three VCs are present in memory and responding to messages. All three VCs are instantiated the same way:
//Initialize the tab bar view controllers
vc1 = [[VC1 alloc] init];
vc2 = [[VC2 alloc] init];
vc3 = [[VC3 alloc] init];
tabCon = [[UITabBarController alloc] init];
//Install the tab bar
NSArray *viewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3,nil];
[tabCon setViewControllers:viewControllers];
[vc1 release];
[vc2 release];
[vc3 release];
Any thoughts on a likely cause would be very much appreciated.
Well, I'm afraid the solution won't really be helpful to anyone that runs into a similar issue.
Turns out I had a conditional I'd forgotten to disable that forced the tabbarcontroller to flip to tab 1 if certain conditions were not met in tab 0.
So, I'm having some issues with my implementation of the Three20 TTLauncherView. I am using their code, not a fork (although I have heard of rodmaz's version), and I can't get it to work properly. This is what my app looks like.
alt text http://img709.imageshack.us/img709/8792/screenshot20100715at409.png
I removed the icon image, that's not the issue. The issue is, at the top there is no Navigation bar at all, and I believe also causes the white strip at the bottom, which appears to have the same dimensions as a Nav Bar. I've spent quite a while looking through their code and can't figure this out at all. It looks like their Navigation bar (as seen in their Catalog example app) stems from the TTTableViewController, or something further up. However, my app starts like the Facebook app does, not into a table, but into the TTLauncherView. So... how do I get the Navigation bar into my TTLauncher view, if it goes "App Delegate -> TTLauncherView Subclass"
Thanks for your help!
Edit:
Added the code I used. I put this in my app delegate, wrapping my first view with the UINavigation Controller, and it worked just as I wanted!
MainViewController *aController = [[MainViewController alloc] initWithNibName:nil bundle:nil]; //my Main view
self.mainViewController = aController;
[aController release]; //release for Memory Management
self.mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
UINavigationController *navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:self.mainViewController animated:NO]; //Gets the main view on the screen
[window addSubview:navigationController.view];
You simply wrap the view with a navigation bar before you push the new view. As an example, here is a snippet of my code where I present a modal view controller with a navigation bar.
- (IBAction) showNewNavView: (id) sender
{
// Present it as a modal view and wrap the controller in a navigation controller to provide a navigation bar for the Edit and Save buttons
ModalViewController *addController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
addController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[addController release];
}
If you want to add any buttons or set the title of it, you need to do that in the viewDidLoad method of the view that you are pushing (i.e. your TTLauncher view)
I have a menu screen that implements UINavigationController and on top of that screen, using presentModalViewController, I place another screen on which I want to have another UINavigationController. I have tried to implement another navigation controller to handle the new screen but I either get a navbar 1/8th the way down the screen and it crashes or nothing at all. I have tried [[UINavigationController alloc] initWithRootViewController:navigationConroller] with no success as well. I'm just using pushViewController to try and place the next nib on the stack which doesn't work. What am I doing wrong?
Although there are a lot of people saying on forums that Apple doesn't allow this I have got it to work. What you have to do is:
Map *mapScreen = [[[Map alloc] init] autorelease];
mapScreen.delegate = self;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:mapScreen] autorelease];
[self presentModalViewController:navController animated:YES];