Branching off from a tab bar controller? - ios

I've got 3 view controllers. Two I have hooked up to a tab bar controller and one that I'm wanting to access when a user selects a cell on the second view controller in my tabbed views.
I'm wanting when the user hits "back" on the 3rd "detail" page for the user to be taken back to the 2nd view.
When I do this by just adding a button and segueing back to the 2nd VC, the tab bar is gone. I tried in my viewDidAppear to unhide the tab bar, but I guess going off of the tab bar controller messes up the navigation.
I tried creating a variable that was like "didHitBack" and on my "back" button on the 3rd view I'm creating a segue back to the Tab Bar Controller, and if "didHitBack" is true I do
_ self.tabBarController?.selectedIndex = 1
which takes me to the second page, but it's loading the first view in then going to the second page which looks bad.
I was thinking maybe there was a way to do "didHitBack" and setting the tab bar's initial view controller to the second one or something, but that all just seems very wrong.
Is there a "proper" way to do this?
To recap I have VC1 and VC2 that are hooked up to a Tab Bar Controller, I have a tableview on VC2 that on didSelectRow I'm going to VC3 which I do not want to be a part of the tabbed view controller, and when I hit back on VC3 I want to go back to VC2.

If you want to build a navigation stack, you should embed your view controller in a UINavigationController
So your tab bar would be hooked up to VC1 and NavVC. The root view controller of NavVC would be VC2.
You can then push a new view controller onto the stack using the navigation controller (or pop the view controller to go back) all within the confines of the tabBar.

Related

Pushing viewController which is not in tab controller without hiding the tab bar

I have a tab controller in which five viewControllers are there. I even have a side menu bar which has the list of other viewControllers . My problem is when i try to click any list to move to viewController it get pushed over the screen, hiding the tab bar at the bottom. How can i show the tab bar at bottom for this scenario. I got some ideas but it dint helped.
You need to make sure that your tab bar controller is you root view controller.
Your story board should look like
tabbarController -> NavigationController -> VC1 -> VC2
Your VC1 to VC2 segue has to be a show segue, not a present modally because the second one makes V2 the root view controller.

Why Do I Need A Second Navigation Controller?

I have the following on my storyboard:
A navigation controller with a table view controller as its root view controller.
The table view controller's navigation item has right bar button (Add) that segues to a 2nd navigation controller.
The 2nd navigation controller has a 2nd table view controller as its root view controller.
The 2nd table view controller's navigation item has a left bar button (Cancel) and a right bar button (Save) both of which unwind back to the 1rst table view controller.
This all works fine: I can navigate from the 1st table view controller to the 2nd and back.
If I remove the 2nd navigation controller and instead segue directly from the 1st table view controller to the 2nd then the 2nd table view controller's navigation item is not displayed. What is going on? Why do I need the 2nd navigation controller?
remove the intermediate navigation controller and connect your second VC to initial vc and change your segue type kind model from present modally to show e.g push
if you are using present then navigation controller is not a manodatry but on your save and cancel button purpose you need to embed with navigation controller, in here you push then no need of Second Navigation Controller.
on navigation use
[self performSegueWithIdentifier: #"sample" sender: self];
on your second by default navigation bar will comes, if you need add barbuttons in right and left side, once press the done button use the following comment
[self.navigationController popToRootViewControllerAnimated:YES];
it automatically come back to initial VC,
you can get the detail of segues in apple
You don't need a second navigation controller. This is what you need to do to after you do a Show segue to the second TableViewController:
Confirm that you're actually doing a Show (e.g., Push) segue. If you have to do a Present Modally segue, then you will need another UINavigationController.
Add a Navigation Item (not a Navigation BAR) to the second TableViewController. You'll then be able to add a title, add navigation buttons, etc.

Why is the tab bar not appearing throughout the app?

I have implemented a tab bar, but as I go through the app I am not seeing the tab bar. It disappears after I go to a certain page. This is how I implemented it. I have a tab bar connected to a vc which is embedded inside a navigation controller. So the hierarchy looks like this.
----UITabBarController
-------UINavigationController
-----------ViewController 1 with button to view controller 2 (I can see the tab bar)
----------------View Controller 2 (I can't see the tab bar)
It sounds like the segue that you get from view controller 1 to view controller 2 is a "present" segue, rather than a "push" segue. (If I recall correctly, Apple removed "push" segues from Storyboards recently.) Sadly, "present"ed view controllers appear in front of the navigation controller.
In order to do a "push" segue, you have to do it in code, e.g.:
- (IBAction)buttonTapped: (id)sender
{
ViewController2 *viewController = ...
[self.navigationController pushViewController:viewController];
}
i think you missed to initial tab bar as initial view controller

How to prevent tabbar from hiding with SWRevealViewController?

I'm trying to find out why any ViewController, that I push onto navigation stack does not show tabbar. Now I have construction like this:
loginVC -> navigationController -> SWRevealVC --> (leftPanelVC and second segue is to tabbarController, which has 4 its own view controllers). When I push view controller from any of this 4 controllers I'm loosing my tabbar and I cannot bring it back. Tried hidesBottomWhenPushed but it didn't work out as expected. Anybody?
EDIT:
What I just tried, was to set connections like this: login -> tabbarcontroller -> as first subcontroller I set up SWRevealViewController and hooked to it front navigationController and rear tableController. Unfortunately it messes stuff a bit, because tabbar now stays always, even on top of rear controller... the look I'm trying to get is interaction like in facebook app, where tabbar is always visible, but as a part of front controller, not overlaying rear.
When I push view controller from any of this 4 controllers I'm loosing my tabbar and I cannot bring it back.
I am not sure what you are doing here, but as far as I understand, you have:
pushed a tab bar controller on to a navigation controller;
from that tab bar controller, pushed a new view controller on to the navigation controller.
It that is correct, than it is normal that your tab bar controller tab bar "disappears" since you are pushing a new view controller (point 2) on to the navigation controller and this will replace the tab bar controller as the top most controller in your navigation controller.
Possibly, what you are looking for can be obtained by embedding a navigation controller inside of a tab bar controller, but I do not have enough info about your UI to be sure this makes sense.

(iOS) Why does second 'push' segue in navigation controller always crash?

I have a storyboard setup as a Tabbed Application with first view controller containing a
UITableView. The Protoype cell has a "push" segue to detail view which is embedded in a navigation controller. So far so good. The detail view pushes when a cell is selected and there is a navigation bar item to get back to the table view.
Now I run into trouble. The detail view has 2 buttons "Map" and "Ticket". If I create a new UIViewController, embed it in a navigation controller, and ctril-drag a 'push' segue from a button to the new view controller as before, the app crashes instantly with a SIGABRT when I click the button. If I don't embed in nav controller and use a 'modal' segue instead it doesn't crash but it seems a natural flow to continue with the 'horizontal slide' animation and the nav bar button back to the detail view.
Once I can stop that crashing I would like to connect the other button to it's own view controller with a UIMapView.
What am I doing wrong?
You don't need to embed a navigation controller in the detail view. You only need one at the top level. Take out the navigation controller in the detail view controller and just do a push from there to the next view.

Resources