In my tab based app, I programetically created the tabbar app with 4 tabs. In my first tab there is 5 scrren & in 3rd tab there is 3 screens.
On my first tab's 2nd screen when i click one button i want it should go to 2nd screen in 3rd tab. But now it go to the screen which is last open on 3rd tab.
e.g. tabControllers: a,b,c,d
a tab: 1->2>3>4>5
C tab: 1>2>3
I want selected tab is a: & screen is: 3 &
click button on that screen go to
selected tab is C & screen is 2nd
reference link is:
Change the selected TabBar index on button click
My code is as follow:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//for home tab..
UINavigationController *nav1 = [[UINavigationController alloc] init];
UIViewController *viewController1 = [[[CarAccidentAppViewController alloc] initWithNibName:#"CarAccidentAppViewController_iPhone" bundle:nil] autorelease];
nav1.viewControllers = [NSArray arrayWithObjects:viewController1, nil];
//for steps tab...
UINavigationController *nav2 = [[UINavigationController alloc] init];
UIViewController *viewController2 = [[[FirstSteps alloc] initWithNibName:#"FirstSteps" bundle:nil] autorelease];
nav2.viewControllers = [NSArray arrayWithObjects:viewController2, nil];
//for profiles tab...
UINavigationController *nav3 = [[UINavigationController alloc] init];
UIViewController *viewController3 = [[[Profiles alloc] initWithNibName:#"Profiles" bundle:nil] autorelease];
nav3.viewControllers = [NSArray arrayWithObjects:viewController3, nil];
//for contact us tab...
UINavigationController *nav4 = [[UINavigationController alloc] init];
UIViewController *viewController4 = [[[ContactUs alloc] initWithNibName:#"ContactUs" bundle:nil] autorelease];
nav4.viewControllers = [NSArray arrayWithObjects:viewController4, nil];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4 ,nil];
self.window.rootViewController=self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
//Button click event
-(IBAction)btnNewDriverPressed:(id)sender
{
[[NSUserDefaults standardUserDefaults]setInteger:0 forKey:#"showselectedIndex"];
self.tabBarController.selectedViewController=[self.tabBarController.viewControllers
objectAtIndex:2];
}
Sorry you cannot make it work.. if you are in "C" tab with first screen,you will goto second screen by clicking any button only. By pressing c tab,its not gonna load second view controller to your navigation controller without pressing any button. so you need to push to second screen yourself and select the c tab too.. But from my opinion your app design is not good if you do like that. Its not gonna give best user experience.
Please upload your flow with images that explains what you actually want to achieve.
navigate through your desire viewcontroller/screen using initwithnibname method.
Follow :
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:self.viewController animated:YES];
Related
I am developing an application which contains a login page. The first page should be a login page (with a view controller). Once the user has logged in I am going to show another view from that I need to show a tab bar, when the user logs out the same login screen has to be shown. How can I achieve this?
you create TabbarController in your AppDelegete class.when user login successfully then you set Appdelegete TabbarController to RootViewController of your window.
AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate.window setRootViewController:appDelegate.tabBarController];
I have done this type of project but i have made custom tabbar as requirement. After login user have to go to profile page then i use 2nd method but before checking the user has loggedin or not by this 1st method-
if([AppHelper userDefaultsForKey:#"user_id"].length>0)
{
[[AppDelegate getAppdelegate] createTabBar];
}
then you should you this -
-(void)createTabBar
{
self.tabBarController=[[RXCustomTabBar alloc] init];
self.tabBarController.customizableViewControllers = nil;
Home *homeObj = [[Home alloc] initWithNibName:#"Home" bundle:nil];
UINavigationController *tab1Controller = [[UINavigationController alloc] initWithRootViewController:homeObj];
ChatList *chatListObj = [[ChatList alloc] initWithNibName:#"ChatList" bundle:nil];
UINavigationController *tab2Controller = [[UINavigationController alloc] initWithRootViewController:chatListObj];
Settings *settingObj = [[Settings alloc] initWithNibName:#"Settings" bundle:nil];
UINavigationController *tab3Controller = [[UINavigationController alloc] initWithRootViewController:settingObj];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: tab1Controller, tab2Controller,tab3Controller, nil];
self.tabBarController.selectedIndex=0;
self.tabBarController.delegate = self;
[self.tabBarController selectTab:0];
self.window.backgroundColor=[UIColor clearColor];
self.tabBarController.view.backgroundColor=[UIColor clearColor];
[self.window addSubview: self.tabBarController.view];
}
After this if you have any problem I will be here. Hope this helps.
I would present the log in screen via a modal view. In this case you can implement the tab bar in interface builder for the first view.
I am new to xcode and trying to understand how UITabBarController works. I have been looking everywhere and could not find a straight solution to this question. In the majority of the examples/tutorials that I see, the UITabBarController is defined in the AppDelegate, and then once you launch the app, you see the tab bar right away. In my app, I want to show a welcome screen first, then once you click "Enter" you get to the tabbar view. So the ideal structure of my objects will be the following:
MyProjectAppDelegate --> MyProjectViewController --> FirstView / SecondView
As far as my understanding, nothing tabbar related should then be declared in MyProjectAppDelegate with this structure. I tried to look at some examples where the UITabBarController is declared in the AppDelegate and do the same in the MyProjectViewController, but nothing happens.
For example, I did this in my MyProjectViewController within an IBAction that is connected to the "Enter" UiButton on my welcome screen:
- (IBAction) EnterApp {
[window addSubview:tabBarController.view];
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
FirstView* first = [[FirstView alloc] init];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:first];
SecondView* second = [[SecondView alloc] init];
UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:second];
NSArray* controllers = [NSArray arrayWithObjects:firstNav,secondNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
}
Again, this did not do anything once I clicked on the "Enter" button, even though it does the job in the example where I took it from (where it's within the AppDelegate)
I also tried this on my MyProjectViewController, where the tabbar did show up on the First/Second view, but with no option to customize it (just blank black bars with nothing on them and no idea where to configure them):
- (IBAction) EnterApp {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstView alloc] initWithNibName:#"FirstView" bundle:nil];
UIViewController *viewController2 = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
What went wrong here and what should be the right way to go about doing that? A quick example would be highly appreciated.
Thanks!
I have something similar in one of my apps. At first launch it shows a login screen. After the user successfully logs in, the app switches to a tab bar controlled view.
I do the switching in my appdelegate. The login view sends a notification which the app delegate observes and rebuilds the screen:
- (void)switchView:(NSNotification *)notification {
MyTabbarView *homeView = [[MyTabbarView alloc] init];
NSArray *controllers = [NSArray arrayWithObject:homeView];
[mainNavController setViewControllers:controllers animated:YES];
mainNavController.navigationBar.barStyle = UIBarStyleBlack;
mainNavController.navigationBar.hidden = NO;
[homeView 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 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];
I am new to iphone development.I have created a view based application.Now i want tab bar in that view.The first view of the tab bar is a table view and the second view is the Web-view.All the tutorials explain only tab bar based application.Since i am using view based application i finding it really hard.How to achieve it by using interface builder.please guide me.Any Sample tutorials will be more useful.Please help me out.Thanks.
Try this one. This code for created a tab bar application in programmatically. So clicked the button it will open the tab bar in the view.
-(IBAction) clkBtn:(id) sender
{
UITabBarController *tabbar1 = [[UITabBarController alloc] init];
firstViewController *first = [[firstViewController alloc] initWithNibName:#"firstViewController" bundle:nil];
UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController: first] autorelease];
secondViewController *second = [[secondViewController alloc] initWithNibName:#"secondViewController" bundle:nil];
UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController: second] autorelease];
tabbar1.viewControllers = [NSArray arrayWithObjects:tabItem1, tabItem2,nil];
[self.view insertSubview:tabbar1.view belowSubview: first.view];
[self presentModalViewController:tabbar1 animated:YES];
}
Thanks,
Best of Luck.