Two segues from ViewController and ViewController in Navigation Controller - ios

I have ViewController (VC_1) that is embedded in NavigationController. In VC_1 there is TableView with cells and there is segue from each cell to ViewController with detailed info (VC_2).
So when I touch any cell in VC_1 I get VC_2 with navigation bar and back button.
What if I have separate ViewController VC_3 that is not inside NavigationController. It also has cells with segue to VC_2 with same identifier that VC_1's cell have.
When I get to VC_2 from VC_3 I don't see navigation bar with back button. What are the ways to handle it?

You can place another navigation controller right behind the (VC_3)
Hope this was helpful :)

If you show VC_3 from VC_1 with Show (e.g. Push) segue the Navigation Bar must appear in the VC_3.
What if I have separate ViewController VC_3 that is not inside
NavigationController.
From here I understand that you don't want a Navigation Bar on VC_3. So, you can hide the navigation bar in the viewWillAppear of VC3 and show it again in the viewWillDissappear like in this answer:
How to hide a navigation bar from first ViewController in Swift?
Then, if you do the segue from VC_3 to VC_2 with Show (e.g. Push) you will have the Navigation on VC_2 with no problems.
If after this it still not working, check that you are creating well the cell in VC_3 using the dequeueReusableCell withIdentifier method.

Add in a new navigation controller to your story board. Now, change the segues like this:
Vc_1 -> new navigation controller --> vc_3
If tat doesn't make sense this is what i mean, change the segue that is currently going from vc1 to vc3 and make it go to a new navigation controller and then connect that navigation controller and make vc3 its root view controller.

Try putting this in the problematic VC:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
And make sure the segues are using push. :)

Related

How can I transition back to a VC from a navigation controller?

I have a baseVC and a navigation controller.
The navigation controller has a bar button item, which i gave a segue to go back to the BaseVC.
Unfortunately when I press the done button to return to the BaseVC (the initial state from which I went to the navigation controller), the baseVC ends up having the top look as if I went to the extra options navigationVC (a VC which shows more info on content in cells in the main navigation controller)
How can I prevent this?
This is done on the interface builder.
Update:
I have found that my issue is related to this one...
for back to root viewController use
navigationController?.popToRootViewController(animated: true)
for back to previous viewController use
navigationController?.popViewController(animated: true)

How to keep NavigationController when performSegue from embeded tableviewcontroller

In the bottom left viewcontroller i have a searchbar at the top that call the tableview at the top , the problem is that i want to segue to the right viewcontroller with detail of it, but of course i'm losing my navigationController so when i'm into the right viewcontroller i can't go back anymore, how should i do to go back to my original Viewcontroller ?
Add Navigation Controller as the starting view in storyboard. And then Link RootViewController to it. This will ensure navigation bar in all the views coming next.
you may hide navigation bar in the view where not needed as
self.navigationController?.isNavigationBarHidden = true
push newViewController instead of presenting
Also please check, if you are presenting it modally. Modal segues take over the whole screen, so any navigation bars, tool bars, or tab bars that are in the presenting controller will be covered up. If you want a navigation bar on this modal controller, you'll need to add one specifically to it, and add any buttons you want to that new navigation bar (or tool bar). If you don't want to do this, then don't present it modally, do a push to it.

swrevealviewcontroller navigation item and bar button missing

hello I have implemented SWRevealViewController in my swift app. The problem I am having is If I set SWRevealViewController as my initial ViewController all works fine. But If I launch this controller through code
let nav : UINavigationController = UINavigationController(rootViewController: self.storyboard!.instantiateViewControllerWithIdentifier("swrevealviewcontroller") as UIViewController)
self.navigationController?.presentViewController(nav, animated: true, completion: nil)
the navigation Title and barButtonIcon Disappears which is in my case is a hamburger menu icon.
SWRevealViewController is connected to the HomeViewController. and I am initiating SWRevealViewController when user clicks the login Button.
If you need more information regarding the storyboard screenshot let me know. I'll upload here.
Updated:
storyboard
navigation controller's navigation bar will only show up for view controllers that are contained by that navigation controller. Here, you're presenting a modal view. It's not contained by the navigation controller.
If you want the navigation bar to continue to appear:
If it's purely a matter of style, put a navigation bar on the modal scene you're presenting in the interface builder.
If you need to modally present a view that should be contained in a navigation controller, then you need to present a navigation controller--not a view controller.
Finally, if the view you're presenting is intended to be part of the navigation controller's navigation stack, then you need to present it with a push, not a modal segue.
Update
Do like simple ,
and call the perform segue as
[self performSegueWithIdentifier:#"main" sender:self];
I solved my problem by pointing Navigation Controller first and Tab Bar Controller second. Please, see the picture below.
Hope this help!..Thanks...

How do I add a back button to a navbar in a uiviewcontroller?

I have an app with a uitabbarcontroller with 2 tabs.
The first tab is a mapview in a uiviewcontroller with pins that i need to call a detail tableview controller.
The second is a tableviewcontroller with a list of the same locations as before that I need to call the same detail tableview controller.
Ive added the detailVC to storyboards and added a navbar to it. how do I add a back button to that navbar that will return to the calling vc (mapview or listvc)?
I would add a segue from both the pin (pinToDetailVC segue identifier) and the list cell (cellToDetailVC), so I could add unwind segues to return to the proper vc. But I cant seem to add the back button to the navbar.
Here is what it looks like...
You want to embed the 2 view controllers into a UINavigationController, then the second view controller is pushed into the navigation controller. Then you don't need to explicitly add the back button as it will automatically be added for you. You also wouldn't need to add the unwind segues.

Push segue from a view controller controlled by UITabBarController

Let's assume that a first view controller is connected with a UITabBarController and I want to make a push segue to the second view controller from this first view controller.
From my googling, it seems that a modal segue from a view controller connected with a UITabBarController hides the bottom tab bar, while a push segue doesn't.
However, my push segue is also hiding my tab bar in the second view controller. I have overridden prepareForSegue method in the first view controller.
Below are images of my storybard and the simulator. Anyone has an idea why this is the case? Thank you in advance for your helps.
Your trouble is because your tabViewController is embedded in the navigation stack that you initialise with your login screen.
you need to rearrange things so that each of your tab bar controller tabs opens to a new navigation stack.
What I suggest
your loginscreen should navigate to your tab bar controller with a modal/presenting segue, not a push segue. Remove the navController that encloses the loginscreen, you don't need it (well, even if you keep it, don't use a push segue, use a modal segue, and you won't then be referring back to that navController's viewController stack from inside your tab bar).
embed each of the first viewControllers in your tabViewCOntroller inside a separate navController.
Now you can push segue within your tabViewController's tabs.

Resources