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
use a
UIBarButtonItem
with aUIButton
as a custom viewdisable 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
One Step Affine Transform for Rotation Around a Point
Objective C: Downloading File with Progress Bar
How to Use Nslocalizedstring Function with Variables in Swift
Scrollview Gesture Recognizer Eating All Touch Events
Capturing and Storing a Picture Taken with the Camera into a Local Database/Phonegap/Cordova/Ios
Uidatepicker Select Month and Year
Custom Init for Uiviewcontroller in Swift with Interface Setup in Storyboard
What Is "Self" Used for in Swift
Xcode Quits Unexpectedly Every Time I Open My Project
How to Delete Wkwebview Cookies
How to Opt Your iPad App Out of Multitasking on iOS 9
Objective-C Find Caller of Method
Load View from an External Xib File in Storyboard
How to Scroll to the Bottom of a Uitableview on the iPhone Before the View Appears
Drop-Down List in Uitableview in iOS
Xcode Nsmanagedobject Subclass Contains Optionals When They Are Marked as Non-Optional