UIBarButtonItem gets stuck in highlighted state

Originator:dkra89
Number:rdar://35991203 Date Originated:December 12 2017
Status:Open Resolved:
Product:iOS SDK Product Version:11.2
Classification:UI/UX Reproducible:Always
 
Area:
UIKit

Summary:
The righBarButtonItem of a UINavigationBar gets stuck in the highlightedState of the button if created with UIBarButtonItem(title:style:target:action:). It works if a customView is set for UIBarButtonItem.

Steps to Reproduce:
1. Create a UIBarButtonItem via UIBarButtonItem(title:style:target:action:)
2. Set the created button as rightBarButtonItem on a navigationBar.
3. Make the action of the barButtonItem trigger a push on the navigationController
4. Press the righBarButtonItem
5. Press the back button in the UINavigationBar

A working example is attached as playground.

Expected Results:
The rightBarButtonItem should be in normal state and look like it is enabled.

Actual Results:
The rightBarButtonItem stays in the highlighted state and looks disabled.

Version/Build:
iOS 11.2

Configuration:
Comments



Source of the originally attached playground:

import UIKit
import PlaygroundSupport

class MyViewController : UIViewController {
    
    init() {
        super.init(nibName: nil, bundle: nil)
        let editButton = UIBarButtonItem(title: "push",
                                         style: .plain,
                                         target: self,
                                         action: #selector(push))
        
        
        navigationItem.rightBarButtonItem = editButton
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError()
    }

    override func viewDidLoad() {
        view.backgroundColor = .white
    }
    
    @IBAction func push() {
        let next = MyViewController()
        navigationController?.pushViewController(next, animated: true)
    }
}

// Present the view controller in the Live View window
let navigationController = UINavigationController(rootViewController: MyViewController())
PlaygroundPage.current.liveView = navigationController
PlaygroundPage.current.needsIndefiniteExecution = true

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!