I have a view controller in a navigation controller. In viewDidLoad
:
let button = UIButton()
button.setImage(Theme.Icon28.back.withRenderingMode(.alwaysTemplate), for: .normal)
button.addTarget(self, action: #selector(didTapBackButton), for: .touchUpInside)
button.imageEdgeInsets = Constants.buttonImageEdgeInsets
button.accessibilityIdentifier = "nav_btn_back"
navigationItem.leftBarButtonItem = button
This sets up my custom back button. Now I want to push a UIHostingController
:
navigationController?.pushViewController(UIHostingController(rootView: SomeView()), animated: true)
With SomeView
as:
struct SomeView: View {
var body: some View {
Text("Hello World")
}
}
Now when I push the UIHostingController
the back button will change back to the default system back button, the leftBarButtonItem
has lost my custom button. Has anyone else run into this issue?
Why is it overriding my custom button?