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

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)

Related

Navigation bar disappear after segue

I'm trying to adding a navigation controller and to associate it with the home (and of course the controllers that are connected to the home)
this because i prefer to not have the navigation controller in the first 3 VC (storyboard entry, login and sign up). My problem is that after a simple self.performSegue(withIdentifier: "goToHome1", sender: self) from one of the first three VC the navigation bar disappear, is the first time i'm going to add a navigation controller and until now i always used only this formulaself.performSegue(withIdentifier: "goToXcontroller", sender: self) to switch from one controller to another so maybe i have to change something to fix this problem? I also tried to find some tutorial about NC but i didn't find something clear that help me with this.
You have to create segue to your UINavigationController instead of home view controller. You are skipping navigation controller by directly using segue to home view controller.
Rootviewcontroller of your navigation controller is Home view controller. So if you create a segue to your navigation controller, it will open your home view controller with navigation bar.

Swift / iOS. Remove few view controllers from navigation stack

Here is what I want to do and I am not sure is it right approach, so please give me an advise how to do it.
I have Initial VC with Navigation VC, from it I push First VC, from it I push Second VC.
Next I present (from NavigationController of Second VC) Third VC.
And now I want to remove First and Second VCs from navigation stack.
After that I expect to have such result: I dismiss Third VC and I see Initial VC
How can I get that result?
You can remove view controller from navigation stack by function:
navigationController?.viewControllers.removeAtIndex(*index of view controller you wanna remove*)
You can go back to the initial view controller by calling UINavigationController.popToRootViewController(animated: Bool)

Two segues from ViewController and ViewController in Navigation Controller

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. :)

Adding a Back Button on A Table View Controller

I am interested in implementing a back button to segue to a previous view controller. I have tried to embed a navigation bar onto the the top of the table view controller but the issue is when I do segue back to the first view controller, by default, Xcode keeps the navigation bar with a back button to go back to the table view controller. Is there a simpler way to implement a segue to go back to the first VC without the navigation bar remaining?
I'm not too sure if this works, but embed your view controllers including the first one inside the navigation controller. That would make all your view controllers with navigation bar above.
On the main view controller (the one you do not want to have the navigation bar), add the line of code inside your viewDidLoad method.
Swift 3:
self.navigationController?.navigationBar.isHidden = true
I found an easy way. On your TableViewController, drag a UIview to the top of the view controller and itll let you insert the view. From there just add your back button
Just assign your "Back" UIBarButtonItem to this method and it should work.
#IBAction func backButtonPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
Sounds like a few problems
1) How are you navigating from the first view controller? Is it with Show (Push) if not, you are replacing the first view controller in your stack.
2) Based on your problem, make sure your first view controller is not embedded in a navigation controller
3) As Dylan mentioned, you need to hook your back button to remove the current view controller to return to the first one
4) Extension of (3), how are you segueing back to the first view controller? If you are explicitly navigating to first view controller with your back button handler, it's not actually going back but rather forward and keep the navigation bar.

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...

Resources