Reputation: 555
I have two viewcontrollers. The first viewcontroller is collection view controller and i set self.navigationController?.hidesBarsOnSwipe = true
in viewDidLoad()
.
When I push the second viewController
from the visible cell of collectionView, the navigation bar is showing in the second viewController
but if I scroll the collectionView cell and when push the navigation is not showing.
Can anyone tell me what the problem is?
Upvotes: 1
Views: 2740
Reputation: 2727
scrolling is done via swipe gesture, so it triggers your code:
self.navigationController?.hidesBarsOnSwipe = true
because navigation controller is shared between all view controllers presented on top of it, it's properties (like hidden bar) preserves pushing / popping.
Common pattern is to change it's state in overrided lifecycle methods, eg:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.hidesBarsOnSwipe = false
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
and reverting those state in viewWillDisappear
Upvotes: 3
Reputation: 131
When this property is set to true, an upward swipe hides the navigation bar and toolbar. A downward swipe shows both bars again. If the toolbar does not have any items, it remains visible even after a swipe. The default value of this property is false. (get it from apple)
See the doc https://developer.apple.com/documentation/uikit/uinavigationcontroller/1621883-hidesbarsonswipe
It means when you swipe up it will hide and when swipe down it will shown. That's the reason.
To fix it you can add following code to the other controller
[self.navigationController setNavigationBarHidden:NO animated:YES];
Upvotes: 1
Reputation: 3465
Put this self.navigationController?.hidesBarsOnSwipe = false
and this self.navigationController?.setNavigationBarHidden(false, animated: true)
in your second view controller.
You might want to move your self.navigationController?.hidesBarsOnSwipe = true
from viewDidLoad
to viewWillAppear
in your first view controller.
Upvotes: 0
Reputation: 14504
Don't get much insight what exactly you implemented, but try to unhide navigation bar in second view controller.
Add below code in viewDidLoad method of second View controller.
self.navigationController?.isNavigationBarHidden = false
Upvotes: 0