Losing Reference to UITabBarController On UINavigationController Push - ios

Currently I'm using storyboards to segue between controllers. I have a UITabBarController with a UINavigationController for each tab.
All my root UIViewControllers in their UINavigationControllers return the following when I log out the tab bar controller:
Tab Bar Controller: <UITabBarController: 0x7f7ff958d3b0>
However when I programmatically push in a new VC in the following manner:
//Show New VC
UISecondViewController *secondController = [[UISecondViewController alloc] init];
[self.navigationController pushViewController:secondController animated:YES];
and log out the tab bar controller in secondController, I see:
Tab Bar Controller: null
What's going on here?
Update:
At first I thought it could be an issue with using multiple storyboards, but when I push secondController in store.storyboard using a storyboard segue it works perfectly. The problem is this subclass controller I'm trying to push was built to only work programmatically (third party).
Main.storyboard
Store.storyboard

Related

Can't push to View Controller from AppDelegate without losing Navigation Bar and Tab Bar setup iOS

I try to push to specific view controller from app delegate without losing previously set navigation bar and tab bar items setup.
As presented in my Main storyboard:
After 1 action performed in TypeNameVC, on app relaunch I want to skip LogInVC and TypeNameVC in didFinishLaunchingWithOptions in AppDelegate forward to MapViewController or any other VC of Tab Bar Controller.
This code initializes new Navigation Controller with new Navigation Bar and Tab Bar Controller is missing.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
//To instantiate Main.storyboard.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
//To instantiate VC to go to.
MapViewController *mapVC = (MapViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MapViewControllerID"];
//To push to instantiated VC.
[navigationController pushViewController:mapVC animated:YES];
I tried to performSegue using segue to Tab Bar Controller but on Navigation Controller stack there is only LoginViewController (I checked it with [navigationController viewControllers])
I read through entire Stack Overflow, I made dozens of combinations but I can't figure out the solution. I would appreciate any help/advice.
UPDATED QUESTION
Screen: screen
Have a look to the screen image. First row of screen shows how it looks like if I navigate "normally". Second row shows what happens if I push to MapVC from AppDelegate. What I need is to skip first two VC's with maintaining Navigation and Tab Bar bars setup.
When I navigate "normally" Tab Bar Controller and it's VC's get correctly allocated.
2016-06-08 12:37:44.394 Checkpoint[4196:1034786] Navigation Controller VC's: (
LogInViewController: 0x135d50b00,
TypeNameViewController: 0x135f455b0,
UITabBarController: 0x135f1d180
)
2016-06-08 12:37:44.394 Checkpoint[4196:1034786] Tab Bar Controller VC's: (
MapViewController: 0x137078cf0,
PlacesTableViewController: 0x135f1d7d0,
FriendsTableViewController: 0x137083350
)
When I push directly to MapVC they don't. I do get the point what's going on but I know how to code that solution.
Navigation Controller VC's: (
LogInViewController: 0x15fd5ccf0,
MapViewController: 0x15fd6ffa0
)
2016-06-08 12:31:53.813 Checkpoint[4187:1033755] Tab Bar Controller VC's: (null)
Customize your class MapViewController for visible Navigation Bar and Tab Bar:
- (instancetype)init
{
// init code
self.hidesBottomBarWhenPushed = NO;
retur self;
}
-(void)viewWillAppear:(BOOL)animated
{
// some code
[self.navigationController setNavigationBarHidden:NO];
}

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.

How to Push A view with TabBarController as Root

I'm starting out with iOS Development.
Currently, I've implemented a TabBarController that nests 2 Views, one of which has a TableView within in.
I'm trying to get the table view to Push another view when DidSelectRow is called.
What I am trying to do is similar to the AppStore in the Search Tab.
I.E:
When you find the App you want you tap on the table row - then the search bar fades away and the Navigation bar fades in, revealing more detail.
Right now I'm trying this:
self.nav = [[UINavigationController alloc] initWithRootViewController:rootVC];
nav.delegate = self;
self.detailView = [[detailView alloc] initWithNibName:#"detailView" bundle:nil];
[nav pushViewController:self.detailView animated:YES];
Where rootVC is the viewController in my secondView.
This does nothing. I've called NSLog to make sure that the method is being called, and it is.
Any help is greatly appreciated.
Thanks!
Do you have a navigation controller in the app? One way to achieve the navigation controller with tab bar controller is to add navigation controller for each tab bar item . Then make the root view controller of the navigation controller one of your 2 views controllers.

Resources