Currently i am working in iPhone app, i have four screen like Login, A,B and c etc..
User enter the username and password field in login screen, then press login button
-(void)LoginButtonMethod
{
A *a = [[A alloc]init];
B *b = [[B alloc]init];
C *c = [[C alloc]init];
UINavigationController *navi1 = [[UINavigationController alloc] initWithRootViewController:a];
UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:b];
UINavigationController *navi3 = [[UINavigationController alloc] initWithRootViewController:c];
UITabBarController *TabBar = [[UITabBarController alloc] init];
TabBar.delegate = self;
TabBar.viewControllers = [NSArray arrayWithObjects:navi1, navi2, navi3, nil];
navi1.tabBarItem.title=#"A";
navi2.tabBarItem.title=#"B";
navi3.tabBarItem.title=#"C";
[self.navigationController pushViewController:TabBar animated:YES];
}
Then i have set navigationbar title for each class like A as facebook, b as yahoo, c as google.
Finally i run the application, tabbar title showing in A,B,C
Then i select 3rd tabbar item (C), at the time that tabar title change google.
i can't fix this, please help me.
Thanks in Advance
Apple in it's developer documentation states following:
"You never want to push a tab bar controller onto the navigation stack of a navigation controller. Doing so creates an unusual situation whereby the tab bar appears only while a specific view controller is at the top of the navigation stack. Tab bars are designed to be persistent, and so this transient approach can be confusing to users."
try presenting it
[self presentModalViewController:tabBar animated:YES];
You can push Tabbar to Controller By
Either
[self.navigationController pushViewController:tabBar animated:YES];
or
[self presentModalViewController:tabBar animated:YES];
Hope this will fix your problem
in this
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
Method of each view Controller put the following code..
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Comment" image:[UIImage imageNamed:#"Icon-AddComment.png"] tag:0];
self.navigationItem.title = #"Comment";
it Works
Related
My UITabBar is not completely showing after I present a UITabBarController from a UIViewController. Please can you tell me what I am doing wrong?
My code is:
//some method
LoggedInViewController *lvc = [[[LoggedInViewController alloc] initWithAccount:account] autorelease];
[self presentModalViewController:lvc animated:YES];
- (void)viewDidLoad
{
self.tabController = [[UITabBarController alloc] init];
LoggedInFeedNavigationController *navController = [[LoggedInFeedNavigationController alloc] initWithAccount:self.account];
[self.tabController setViewControllers:[NSArray arrayWithObject:navController]];
[self.view addSubview:self.tabController.view];
[super viewDidLoad];
}
It's not a good practice to do:
[viewController1.view addSubview:viewController2.view];
The point of the MVC design is lost. The view controller should get your data (from the model) and put it in the view. If you have more than one view just arrange the functionality of the views to accept the corresponding data.
So if you need a tab bar controller you should do the following:
// assuming you are in the same initial controller
UITabBarController* pTabBarControllerL = [[UITabBarController alloc] init];
MyFirstController* pFirstControllerL = [[MyFirstController alloc] init];
[pTabBarControllerL setViewControllers:[NSArray arrayWithObject:pFirstControllerL]];
// perhaps set more tab bar controller properties - button images and so on
[self presentModalViewController:pTabBarControllerL animated:YES];
// release the memory you do not need
-(void)viewDidLoad {
// do your work in pFirstControllerL
}
PS: You should not subclass UINavigationController and UITabBarController.
Actually according to the Apple's recommendations UITabBarViewController should be the root in the UIWindow hierarchy. We had hard times trying to put TabBar VCs or Navigation VCs not to the root.
I've been stuck trying to puzzle this out for a couple days now, and I'll admit I need help.
The root view controller of my application is a tab bar controller. I want to have each tab bar a different navigation controller. These navigation controllers have completely different behavior.
So how do I set this up in terms of classes? Per Apple's documentation, I'm not supposed to subclass UINavigationViewController. So where do I put the code that drives each of these navigation controllers? Does it all get thrown in App Delegate? That would create an impossible mess.
This app should run on iOS 4.0 or later. (Realistically, I can probably require iOS 4.2.)
This is taken from one of my applications. As you say, you are not supposed to subclass UINavigationController, instead you use them as they are and you add viewcontroller on the UINavigationController's. Then after setting the root viewcontroller in each UINavigationController, you add the UINavigationController to the UITabBarController (phew!).
So each tab will "point" to a UINavigationController which has a regular viewcontroller as root viewcontroller, and it is the root viewcontroller (the one you add) that will be shown when a tab is pressed with a (optional) navigationbar at top.
UITabBarController *tvc = [[UITabBarController alloc] init];
self.tabBarController = tvc;
[tvc release];
// Instantiates three view-controllers which will be attached to the tabbar.
// Each view-controller is attached as rootviewcontroller in a navigationcontroller.
MainScreenViewController *vc1 = [[MainScreenViewController alloc] init];
PracticalMainViewController *vc2 = [[PracticalMainViewController alloc] init];
ExerciseViewController *vc3 = [[ExerciseViewController alloc] init];
UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *nvc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
[vc1 release];
[vc2 release];
[vc3 release];
nvc1.navigationBar.barStyle = UIBarStyleBlack;
nvc2.navigationBar.barStyle = UIBarStyleBlack;
nvc3.navigationBar.barStyle = UIBarStyleBlack;
NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nvc3, nil];
[nvc1 release];
[nvc2 release];
[nvc3 release];
self.tabBarController.viewControllers = controllers;
[controllers release];
This is how I go from one viewcontroller to another one (this is done by tapping a cell in a tableview but as you see the pushViewController method can be used wherever you want).
(this is taken from another part of the app)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.detailedAnswerViewController == nil) {
TestAnsweredViewController *vc = [[TestAnsweredViewController alloc] init];
self.detailedAnswerViewController = vc;
[vc release];
}
[self.navigationController pushViewController:self.detailedAnswerViewController animated:YES];
}
The self.navigationcontroller property is of course set on each viewcontroller which are pushed on the UINavigationController hierachy.
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];
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 made two applications that each one of them is tabbar based.
Now I want to combine them to one app that will be struct like that:
-Main menu with 2 buttones.
- button 1: tab bar app no 1.
- button 2: tab bar app no 2.
from each tab bar app, I want an Home button on the left side of the nav bar that will take me to the main menu.
I found this link http://www.pushplay.net/blog_detail.php?id=27 but it's not good to me..
I will be happy if you will able to post some simple code for my problem..
Thanks.
App's 1 & 2 need to be based around viewcontrollers, each of which has a tabbar. The root windows can then just alloc/init and then [self.navigationController pushViewController:viewController animated:YES]; to launch the tabbar controller.
If you have relied on IB to build your tabbar applications, its quite difficult to translate them into view controllers. I create my tabbars programatically (i just find it easier) like this
tabBarController = [[UITabBarController alloc] init]; // creates your tab bar so you can add everything else to it
searchTableViewController = [[SearchTableViewController alloc] init];
UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release];
searchMapViewController = [[SearchMapViewController alloc] init];
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release];
atestViewController = [[AboutTableViewController alloc] init];
UINavigationController *AboutNavController = [[[UINavigationController alloc] initWithRootViewController:atestViewController] autorelease];
[atestViewController release];
tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, AboutNavController, nil];
[self.view addSubview:tabBarController.view];