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];
Related
Basically I have
ViewControllerA *aVC = [[ViewControllerA alloc] init];
ViewControllerB *bVC = [[ViewControllerB alloc] init];
UITabBarController *tabBarVC = [[UITabBarController alloc] init];
[tabBarVC setViewControllers:[[NSArray alloc] initWithObjects:aVC, bVC, nil] animated:YES];
Now I can see the two tabs on the tabBarController but when I switch from one tab to another, I can't see any effects, neither on simulator or on real device. From the documentation I should be able to see fading right? Did I miss anything?
If you pass YES to setViewControllers:animated:, UITabBarController will animate the insertion of the the new tab bar items in the tab bar. It doesn't animate the transition between view controllers if the user then switches from one tab to another.
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];
I'm using Navigation-based Application Template with Core Data. Could anyone please tell me how to and a TabBar on the bottom of the view. I am using UITableView, so If I add UITabBar as subview, the TabBar is moving along with tableView when scrolling. I would like to switch between views with TabBar, first "segment" of TabBar should open the RootView (NavigationBar with TableView),and second some other view.
Now I did this:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewController = [NSArray arrayWithObject:yourNavigationController];
self.window.rootViewController = tabBarController
[tabBarController release];
that works fine, but how can I add more Items to UITabBar and for each Item some other view? TabBar has now just one Item on which rootView is loaded
Thanks!
Use UITabBarController as your root view controller in your application delegate:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewController = [NSArray arrayWithObject:yourNavigationController];
self.window.rootViewController = tabBarController
[tabBarController release];
Its simple one, just add UITabbarController to your code and then made the first tab controller to be a navigation controller. And point that navigation controller to your controller which has table view that you want to show.
If you are doing it programmatically you can use this:
FirstViewController *first=[FirstViewController alloc]]init];
UINavigationController *nav=[UINavigationController alloc]]initwithRootViewcontroller:first];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewController = [NSArray arrayWithObject:first];
[tabBarController release];
I currently have a UINavigationController in my app delegate where I push a ViewController on to login. If the login is successful I want to then create a UITabBarController with a Navigation Controller as the first Tab whose root controller is a UIViewController that I am creating.
The RootViewController of my first UINavigationController is actually acting as a delegate to the logincontroller so if a user logs in correctly it calls a method in my RootViewController which is where I would then like to push a UITabBarController onto the stack. Here is my code:
UITabBarController *tbController = [[UITabBarController alloc] init];
FileBrowserViewController *fileController = [[FileBrowserViewController alloc] init];
fileController.pathToFileDB = pathToDBUnzipped;
fileController.parentId = #"0";
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:fileController];
NSMutableArray *aViewControllersArray = [[NSMutableArray alloc] initWithCapacity:2];
[aViewControllersArray addObject:navController];
[navController release];
[tbController setViewControllers:aViewControllersArray];
[self.navigationController pushViewController:tbController animated:YES];
[tbController release];
Now, it is all working fine. Except 2 things. Here is the screen shot:
1) I can't see any uitabbar items. How do i set an image and the text for each tab?
2) I don't want that top black bar. I only want 1 bar ontop with the undo button. How do I remove the additional bar?
I always follow this approach when I have both a UINavigationController and a UITabbarController:
You need to start with a view based application. And then create a UITabbarController in your appDelegate file.
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthesize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
// Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.
I always follow this approach and it never fails. The tabs are always visible. You can make changes according to your code.
to hide the above black bar use -
[self.navigationController setNavigationBarHidden:TRUE];
to set tab bar item use -
for system item -
UITabBarItem *firstItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
for custom item -
UITabBarItem *firstItem = [[UITabBarItem alloc] initWithTitle:#"title" image:[UIImage imageNamed:#""] tag:0];
[navController setTabBarItem:firstItem];
Here is a good video on how to combine Tab Bar, Navigation Bar, and/or Table Views.
http://www.youtube.com/watch?v=LBnPfAtswgw
If you don't want you sign-up screen to have a Tab Bar controller, then you will have to present it as a modal view (since the tab bar is your root view controller). This can be done through the presentModalViewController:animated: method. You can find info about that at:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html%23//apple_ref/doc/uid/TP40007457-CH111-SW1
I hope that helps. Let me know if you have any other questions!
Cheers, Evan.
hi friend that top bar is status bar . You can set.statusbar hidden = yes;
or change it from plist , when you open your plist there is a option to hide it,
I have developed a tab based iphone application.
In this, I am facing a problem as described below:
The view associated with 1st tab bar contains 2-3 buttons. Action of these buttons are to load another view. Now on pressing these buttons the views are loading but in full size(320x480) and hiding the tab bar.
I want to load that view just above the tab bar so that tab bar is accessible.
I explicitly set the view frame in that view's viewDidLoad function, but it is not working.
Please help me out.
Try this :
You need to start with view based application. And then create a UITabbarController in you appDelegate file.
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthsize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.
Rename the tbs as per your requirement. Place 2 buttons in the one of the views which is Navigation controller.
Hope this helps.
Typical application navigation allows the user to freely move forwards and backwards, between tabs etc. This is facilitated by pushing and popping ViewController's on the navigation bar stack.
In certain scenarios you want to force the user to complete some task and this is when you should use a modal view controller. When the application presents a modal view the idea is that the user should NOT be able to navigate away from the view, instead they should only be able to complete or cancel the action and hence the default behavior for a modal view is to hide the navigation bar, tab bar etc.
It sounds to me from your description that you are performing navigation and not a modal task and thus can I recommend using pushViewController instead of presentModalViewController?
If you are only using presentModalViewController because you want a bottom to top animation then you'll need to use a custom animation.