iOS Uinavigationbar Button Remains Faded After Segue Back

iOS UINavigationBar button remains faded after segue back

This is a bug in iOS 11.2 and happens because the UIBarButtonItem stays highlighted after navigation and does not return to its normal state after the other view controller pops.

To avoid this behavior, either

  1. use a UIBarButtonItem with a UIButton as a custom view

  2. disable and re-enable the bar button item in viewWillDisappear(_:) (although this causes the button to appear immediately, use matt's solution to avoid this):


    barButtonItem.isEnabled = false
    barButtonItem.isEnabled = true

Why doesn't bar button change back to blue?

Special thanks to @matt for helping me with this issue.

It seems like this is a bug in iOS, as shown in this answer.

UIBarButtonItem will be always highlight when I click it

Is it a bug in iOS 11.2?

Yes. There's an iOS 11 bug with the right bar button item in the root view controller. When you push to the next view controller and pop back, the right bar button item is dimmed.

That is the bug seen in your screencast. In your code, you set the right bar button item's tint color to white. And initially, it is white. But when you push and then pop, it is no longer white.

What I do is work around this in the view controller's viewWillAppear, as follows:

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.tintAdjustmentMode = .normal
self.navigationController?.navigationBar.tintAdjustmentMode = .automatic
}

Dark shadow on navigation bar during segue transition after upgrading to Xcode 5.1 and iOS 7.1

self.navigationController.navigationBar.translucent = NO; 

For Newer Swift Versions:

navigationController?.navigationBar.isTranslucent = false

iOS9 Navigation Bar Back Button not working

Finally, the problem is solved.
I have been create a new project and use the same method to perform segue and it segued flawlessly. So I excluded the possibility of Xcode might cause the problem. And I found that I have passed the device token for apps at my app delegate by a NSRunLoop, I don't why it will cause such a weird problem, I decide to save the device token at NSUserdefault, then get it at the home page and parse it to server. So it works like a charm now after I take away the NSRunLoop now.



Related Topics



Leave a reply



Submit