ipad Tab bar application with navigation controller - ipad

I am working on an iPad application (with orientation support). I have choose tab bar application for that. I am not finding out how to implement navigation controller in to it for pushing other view controller.
I have to change 1st tab controllers view with another viewcontrollers view I have used following code for changing my view
UINavigationController* theNavController = [[UINavigationController alloc] initWithRootViewController:rootVC];
[theNavController pushViewController:nextVC animated:NO];
// Display the nav controller modally.
[self presentModalViewController:theNavController animated:YES];
My problem is that while doing this my tab bar gets hidden. How can I prevent my tab bar or how can i use navigation bar with tab bar.
Please help me.

Related

How to use custom NavigationBar in ios TabBarController

I'm using a TabController which has a Navigation Controller as it's root and all works fine thus far except i would like to show the NavigationBar of the child viewcontrollers within the tab bar but for now just the tabcontroller's Navigation Bar shows.
This is how the tab bar shows now. with It's NavBar
This is the Navbar of the child ViewController I want to show
Embed a UINavigationController for each tab bar item rather than a UIViewController. You can then make the root view controller of each UINavigationController point to the view controller you want to use for that tab.
This allows each tab to have its own navigation bar and navigation stack.
EDIT
Also, if you intend on keeping your current navigation controller as the initial view controller, make sure you hide it's navigation bar by unselecting "Shows Navigation Bar" in interface builder
or by setting it in UITabBarController:
self.navigationController?navigationBar.isHidden = true
or by setting it in UINavigationController:
self.navigationBar.isHidden = true

Presenting TabBarController's second Tab from NavigationController

I'm trying when I successfully pass from entry viewController (LoginViewController), the Tab Bar open the second tab item. I know how to do it if the Tab Bar was the entry point of the app, with this code in appDelegate.m file:
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setSelectedIndex:1];
but this doesn't help me a lot this time.
I start thinking maybe a solution is to create a custom class for Tab Bar Controller but I m not sure how to do it.
Right now when the user successfully login in, this line of code controllers the segue between LoginViewController(button) and TabBarController.
[self performSegueWithIdentifier:#"loginToTabBarSegue" sender:self];
I found this answer on stackoverflow by DP2 which is the solution of my problem.
This is the line of the code I put in login button when the user successfully login in.
UITabBarController *loadTabBar = [self.storyboard instantiateViewControllerWithIdentifier:#"TabBarViewControllerID"];
loadTabBar.selectedIndex=1;
[self presentViewController:loadTabBar animated:YES completion:nil];
Thanks everyone for your help!
You're using UITabBarController incorrectly. A tab bar controller should never be embedded into a navigation controller. From Apple's docs:
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html
It seems like you want a user to log in before they can use your app. And that the tab bar controller contains the bulk of your app's UI. Consider setting the Tab bar controller as the root view controller of your app and then having the user log in through a modally presented LoginViewController.
Try this to get the tab bar:
UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
[nav.topViewController.tabBarController setSelectedIndex:1];

iOS how to go from xib file to a view controller in tab bar

i have a tab bar application
i am using storyboards and also navigation bar in my app
in my app
FirstViewController (in tab bar) with a button go to the SingleViewController (xib file and not on tab bar)
in SingleViewController there is a button too. and i want to go to one of the controllers which is on tab bar
in singleviewController's button method i have this code:
AylikGirisViewController *controller = [[AylikGirisViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
it goes to the controller but i see a black screen and empty screen also moving to the AylikGirisViewController gets hard (i mean very slowly)
so i think my way is wrong
any ideas for the right way?
if you are using storyboard, you can simply drag another view controller onto the storyboard and give name as SingleViewController, you can easily push the SingleViewController onto the FirstViewController if you embed the FirstViewController in UINavigationController. Use storyboard segue to push the controller. Then you can call UITabBarController Delegate method to show the different viewController.

hide navigation bar throughout the app

I know using below statement I can hide navigation bar.
[self.navigationController setNavigationBarHidden:YES animated:NO];
But I want to do this for whole app.
I don't want to write this statement in all files.
So any idea how can I hide navigation bar for whole project?
If you have used Storyboards, then setting the Navigation Bar to None in the Navigation Controller, and ensuring that the top bar is set to 'Inferred' for all view controllers contained within the navigation controller will ensure that the navigation bar will be hidden for all view controllers in the navigation controller.
You can also use
self.navController.navigationBar.hidden = YES;

Problem with "Presenting a controller modally within a nav controller within a tab bar controller"

My app has two distincts modes. There's a tab bar controller in the app delegate. There are two tabs, both using subclassed view controllers. The two view controllers essentially contain a nav controller each. The nav controllers have their root view controller, and normally when changing screens, I just push and pop controllers of the respective nav controller. This has the (normal) effect that the bottom tab bar is always visible, all great and sound.
This one time I'd like to present a screen modally however, so that the user can't do anything else than confirm or cancel the page using two buttons, ie I want to hide also the bottom tab bar. This would be a case for presenting the view modally I thought, but the view is presented within the nav controller bounds it seems, so the bottom tab bar is still visible, and this causes confusion in navigation the app. I'm not sure how it's possible that the modally presented view is not hiding the tab bar. Most of the questions around here seem to have the problem the other way around (wanting to (incorrectly) present a modal view and leave the tab bar visible).
These are my attempts:
[self presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
[self.tabBarController presentModalViewController:controller animated:YES]; // nothing is displayed. The new controller is instantly deallocated.
[self.navigationController presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
Investigating this, the self.tabBarController is actually nil. There seems to be no link back to the tab bar controller... I guess, to display modally on top of the tab bar, I need to get a link to that tab bar controller?
I seem to have found a solution, I'm not sure it's kosher, because somehow I wasn't able to use the self.tabBarController pointer of the view controller in which I start the view controller call.
What I did was reach for the app delegate, the app delegate having the tab bar controller defined as a public property. I could use that tab bar controller property to modally display my view controller over everything on the screen.

Resources