I have a problem with my navigation bar items. They both have a target to push a view controller, but the problem is that when I go back to the root view controller by dragging to the right, the UIBarButtonItem sometimes stays highlighted after the root controller has appeared. I attach two photos of the navbar:
The behaviour is impredictible, because it only happens sometimes. Does anyone know what's going on and how to fix it?
Thanks!
CodePudding user response:
Most likely this is a bug unfortunately. This happens when you leave the swipe process on the 2nd page without completing
As you know, when you swipe the page, an animation takes place on the barbuttons.As if the alpha of the button is incremented from 0 to 1
This animation effect may cause a bug when you leave the page swipe halfway because there is no problem with the action of the button.
If you change the isEnabled
value of the button in first Viewcontroller , when the page is closed and opened, the problem will be fixed.
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navItem.rightBarButtonItem?.isEnabled = false
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
navItem.rightBarButtonItem?.isEnabled = true
}