I'm trying to prevent some ViewControllers from going back. I have subclassed UINavigationController to make some UI customizations. I conform the UINavigationController subclass to the UINavigationBarDelegate protocol and try to implement the navigationBar:shouldPop method. I have this code:
func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
print("Popping: \(item.title)")
return true
}
When I use the swipe from the left way to go back, the method is called and everything works fine. When I press the back button the method is still called but the ViewController doesn't pop. If the ViewController is the second on the stack the back button dissapears like the navigation bar believes that the popping did occur. Can anyone help me understand this behavior?
You have to pop the view manually:
func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
print("Popping: \(item.title)")
self.popViewController(animated: true)
return true
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With