Navigation bar hides when using popToRootViewControllerAnimated in swift? - ios

In my App, I have to redirect users to my rootview from my login screen.
I used popViewControllerAnimated it just pops only one view.
So i am using popToRootViewControllerAnimated. But when i am doing it the Navigation bar hides.
I referred some links like this & implemented it. But it is of no use.
Tried Code
override func viewDidAppear(animated: Bool)
{
self.navigationController?.navigationBarHidden = false
}
Thanks in advance!

Related

Issue with navigation Bar when switching back to root View controller

I want my app to go back to main root view controller on button click, but when i press the button it goes but the navigation bar is disappeared. I have tried different solutions but no luck.
Try this:
In your Root View Controller, add this code:
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = false
}

Display nav bar when user scrolls down - swift

I have created a parallax detail view in swift. Wish to allow nav bar colour and title display when user scrolls down.
Like this example here on the detail view. This is in objective C and I can't figure out the swift version. I'm sure it's simple enough with a few lines of code in the right place.
https://github.com/KMindeguia/movies/blob/master/README.md
I know the nav bar has a .hideswhenuserswips function but can't find anything for this!
Thanks
If you use storyboard for your UINavigationController, you can set like this
Or, you can set in your code like this:
myNavigationController.hidesBarsOnSwipe = true
You can use scrollview delegate methods to show or hide navigation bar.
you can implement scrollViewDidScroll , scrollViewDidEndDecelerating or scrollViewWillBeginDecelerating.
from this delegate methods you can manage your navigation bar.
This component just using simple UIView and implementing UIScrollViewDelegate methods. You can add your custom view in top of parent view and hide it, implement UIScrollViewDelegate methods and track some contentOffset of uiscrollview. Like in this component from lines 237
scrollDelegate methods
Set the NavigationBar in each viewcontroller, if you would not show navigationbar use this code,
self.navigationController?.navigationBarHidden = true
And show the navigationbar in particular viewController put this below code,
self.navigationController?.navigationBarHidden = false
this lines used your method, or you use this code,
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.navigationBarHidden = true
}
override func viewWillDisappear(animated: Bool)
{
super.viewWillDisappear(animated)
self.navigationController?.navigationBarHidden = false
}
when scrolling to show your navigationbar see this link Hide status bar while scrolling
hope its helpful

Back Bar Button Segue hides Toolbar

I am using a Show segue in my application.
Whenever I segue to another screen and press the back bar button, my navigationController.toolbar disappears.
I tried to get rid of it with
navigationController?.toolbar.hidden = false
in my viewDidLoad().
It doesn't work though. Any ideas?
Please add the code in the viewWillAppear() and it should solve the problem you are facing.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.toolbarHidden = false
}
Remember that viewDidLoad() fires only once during the life cycle of a view controller and in your case , it is in the navigation stack which means it has been already used for that view controller and now when you press back button, it does not work again.
navigationController?.toolbarHidden = false

Swift: how to hide back button on the first view controllers of tab bar controller?

My Tab Bar Controller controls 5 view controllers and I want that in those 5 main pages all the back buttons are disabled and not visible. How can I do that correctly? I have tried all Swift commands seen here in SO but none has worked up to now.
I have tried with
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.hidesBackButton = true
}
override func viewWillAppear(animated: Bool) {
self.navigationItem.hidesBackButton = true
}
but they don't work. I have also tried with
self.tabBarController?.navigationItem.hidesBackButton = true
but this is the strange result
To remove the "back" button from the navigation bar, you can create a UITabBarController class for your UITabBarController in the storyboard, and in that class, inside the ViewDidLoad() method, you can call
self.navigationItem.hidesBackButton = true
This will remove the back button.
The back button is probably added by the navigationcontroller of the tabbarcontroller. So you will have to check the tabbar navigation controller.
Something like this:
self.tabbarcontroller.navigationcontroller.navigationitem.hidesBackButton = true
I think this will resolve the issue. Since the backbutton normally is added by a navigationcontroller, and not by a tabbarcontroller
Update
I have recommended him that he should loose the navigation controllers after the tabbarcontroller. Since the tabbar already implements the navigation needed between the different views. This and hidesbackbutton = true solved his issue

Nav Bar Hidden on View Controller On Second and Subsequent Appearances

I have a parent TableViewController and a child ViewController all within the context of a navigation controller. What I want to happen is for the table view controller to NEVER show the nav bar, and for the view controller to ALWAYS show the nav bar. I hide and show the nav bar within the viewWillAppear func of each subclass, like this:
table view controller:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true);
navigationController?.navigationBar.hidden = true
UIApplication.sharedApplication().statusBarHidden=true
}
view controller:
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = false
}
This works for the first navigation. When I launch the app, the parent table view controller hides the nav bar, and when I select the first cell, the child view controller dutifully displays the nav bar. However, when I touch 'Back' on the nav bar, and then select the cell again, the view controller is no longer displaying the nav bar.
Is there a better way to do this?
Update - as requested attaching screenshots of XIB and Storyboard. Note that there is no XIB for the parent TableViewController. I am not confident that these screenshot will provide much insight. Especially that of the storyboard. Unfortunately, Xcode only has 2 zoom levels:
1. Too zoomed in to be useful
2. Too zoomed out to be useful
Nonetheless, here you have them:
That should work fine: When your ViewController will appear, the code should get executed every time. Try with an "print" to test if that happens.
First View Controller
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
print("viewWillLoad - Table View")
self.navigationController?.navigationBarHidden = false
}
Second View Controller
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
print("viewWillLoad - Detail View")
self.navigationController?.navigationBarHidden = true
}
Ill use that in some applications too.

Resources