Using Tab Bar Controllers iphone iOS5 - ios

Im using the new storyboarding features with ios. I have a tab bar which also has a class name called mytabbarcontroller. However I do not have a seperate class for this as in a .h/.m file for this since all its implementation is in different views which is sorted. Now i have a view controller which appears before the tab bar with an activity indicator. Once it stops it has to move to the tab bar controller. However i cant initialise it with mytabbarcontroller since i dont have .h files to import. Currently it goes to a tab bar controller with nothing on it - basically it creates a new tab bar controller. My code is as follow. I also tried initwithnibname and gave the nib name - i.e mytabbarcontroller. However this throws an error.
UITabBarController *controller = (UITabBarController *)[[UITabBarController alloc] init ];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];

because you are declaring a new UITabBarController, try this instead, import and intialize the first view of the tab bar, for example
FirstSceneController.h
import "FirstTabViewController.h"
...
FirstTabViewController *firstTab = [self.storyboard instantiateViewControllerWithIdentifier:#"mytabbarcontroller"];
[firstTab setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:firstTab animated:YES];
....
and also be sure to add a navigation controller and connect it to your first scene.

Related

Pushing a view controller onto a navigation controller from a tab bar button

I have a tab bar controller with a button like so:
- (void) addButtonPressed:(UIButton *) sender
{
[sender setBackgroundColor:[UIColor regularColor]];
PostViewController *post = [[PostViewController alloc] init];
[self.navigationController pushViewController:post animated:YES];
}
This code runs but the PostViewController is never shown and the tab bar controller remains.
How do I get to push to a new controller?
The NavigationController was created and StartViewController was add as rootController.
Then in StartViewController I have:
TabBarController *tab = [[TabBarController alloc] init];
// Presentation
[self presentViewController:tab animated:NO completion:nil];
in tab bar you need to create separate Navigation Controllers.
Suppose there are 3 tabs A, B and C. All the three tabs have functionality of navigation from one view to another. than you need to create three separate Navigation controllers eact pointing to Tab A, B and C. In this way you can navigate to any class within the specific Tab.
Check out this link for more details.
Hope this will help you. Happy coding :)
You may need to embed your tab bar controller within a navigation controller, In your storyboard click on your tabbarController so that it is highlighted with all the blue lines and then go to Editor in Xcode choose embed IN> UINavigationController ..If you want to do it programatically then in your AppDelegate where you setup your Window just Use This::
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:tabBarController];
navigationController.toolbarHidden=YES;
navigationController.navigationBarHidden=YES;
self.window.rootViewController =navigationController;
if you are using .xib then you have to use NSBundle to load nib
if you are using storyboard then you need to use prepareForSegue to pass on data or just display it out

Navigation Bar & Navigation Toolbar NOT from App Delegate

I'm new to xcode ios 7.
I've struggling a lot with navigation controls building app for iPhone ios7.
I don't want to use storyboard. I prefer to do it programmatically.
What i am trying to do.
I know how to create NavigationBar & Navigation Toolbar via AppDelegate.m
But if it's possible i don't want to do it, because let's assume i want in FirstViewController to show just simple button "Go to Second View Controller" (No Navigation Bar or Toolbar here).
And now in SecondViewController i want to create Navigation Toolbar (bottom) with 4 different tabs linking to ViewControllers!
But the trick is, i want to maintain different Navigation Bar (top) for every ViewController (as you can see in this screenshot).
Here is my Xcode Project File
And here is screenshot form Fancy app showing what i am trying to achieve.
Thanks a lot in advance!
Just to give you an idea, When you tap the button on your first view controller, you can create a UINavigationController and set your second view controller as its root view controller. This way, your first view controller remains no nav bar view and the second view controller holds a Navigation controller. Try something like below:
-(IBAction)goToSecondVC:(id)sender // An action for the button in your first VC
{
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil]; //Init with second view controller
UINavigationController *secondNavVC = [[UINavigationController alloc] initWithRootViewController:secondVC]; // create a navigation controller and set the root as your second view controller
[self presentViewController:secondNavVC animated:YES completion:nil]; // and then present it with anim or no anim..
}

Pushing a UITableViewController from a tabBarController embedded view doesn't remove tab bar?

I have a tab bar controller with 4 tabs and each tab is their own UINavigationController, which is how you're supposed to nest tab bar and navigation controller's together. The initial tab is a TableViewController and works/appears the way that it should. From the tableVC I can push standard view controller's onto the navigation controller with:
[self.navigationController pushViewController:VC animated:YES];
and it works properly.
If I attempt to push another TableViewController onto the navigation with the same method it works the same way, but the initial tab bar does not get pushed off screen like it should, it just stays in place.
Why would the tab bar stay on screen even though I am pushing a new VC onto the navigation?
I have tested with multiple instances of different TableVC's and it only happens with a table view controller.
Here is the code I'm using:
- (void)pushTableVC
{
TestTableVC *tableVC = [[TestTableVC alloc] init];
[self.navigationController pushViewController:tableVC animated:YES];
}
This will push the new table view onto the stack, but the tab bar from the parent VC stays in place and does not get pushed off screen like it should.
You should call the method setHidesBottomBarWhenPushed: on the view controller you are pushing to correctly hide the tab bar.
UIViewController *viewController = [[UIViewController alloc] init];
[viewController setHidesBottomBarWhenPushed:YES];
[[self navigationController] pushViewController:viewController animated:YES];
When you use a UITabBarController, the tab bar always stays on screen, even as you push additional view controllers onto an embedded UINavigationController. You will see this in any app that has a UITabBarController implemented, unless they implement custom behavior to change this.
The UINavigationController contains everything above the UITabBar, but does not contain the UITabBar itself, so it would not be able to push it offscreen.

Add TabBArController to the UIView

Adding tab bar controller to the UIView by [self.view addSubview:tabBarController.view];
is not loaded the content view controllers view, while selecting the tab bar items it crashed. When set the tab bar controller to the root view controller its working fine. How to set tab bar controller into UIView so that I can set another view for some other purpose like iAd?
You just create one tabbar controller in app delegate but don't add it to window, and in view controller you have just add these:
gObjAppDelegate.tabBarController = [[UITabBarController alloc] init];
gObjAppDelegate.tabBarController.viewControllers = #[viewController1, viewController2];
[gObjAppDelegate.tabBarController setSelectedIndex:0];
[self.navigationController pushViewController:gObjAppDelegate.tabBarController animated:YES];
gObjAppDelegate is shared singleton instance of app delegate.This way it worked for me.

UINavigationController pushing UITabBarController only displays one tab

I have an application that has a UITabBarController created in IB. That tbc loads 3 views which work fine up to now.
I decided to INSERT a UINavController as the starting VC and have a UITableViewController display 4 menu items in cells. Each of the 4 items will in essence load the UITabBarController put pass in a different xml file to process in order to display data in those 3 tabs.
I essentially did this at the end of the applicationDidFinishLoading:
MainMenu *rootViewController = [[MainMenu alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.rootViewController = navController;
[window makeKeyAndVisible];
return YES;
I then created the MainMenu as the rootViewController subclassing UITableViewController and added a hardcoded array for now which displays the 4 items I want. I had the didSelectRowAtIndexPath run this code:
tabBarController = [[UITabBarController alloc] init];
[self.navigationController pushViewController:tabBarController animated:YES];
[tabBarController release];
It turns out that when I run it, the navcontroller pushes the tab controller but only the first tab shows up. Here is a pic.
You should never push a UITabBarController from a UINavigationController. Apple clearly says this:
An app that uses a tab bar controller can also use navigation controllers in one or more tabs. When combining these two types of view controller in the same user interface, the tab bar controller always acts as the wrapper for the navigation controllers.`
That essentially means tab bar should be the parent of all other view controllers that get called. Not the other way round. You should probably change the way you present your app.
More information here.

Resources