Can't set a panel item in the left pane of a navigation bar?

I can’t set the custom left button element in the application navigation bar. Here is what I did:

let profileImage = UIImage(named: "researcher_icon_selected")
    let button = UIBarButtonItem(image: profileImage, style: .plain, target: self, action: #selector(self.viewDidLoad))
    self.navigationItem.setLeftBarButton(button, animated: true)    

I put this code in my viewDidLoad of a subclass of UINavigationController called ExpertsNavigationViewController. But nothing is displayed in the navigation bar!

Here are some debugging experiments I tried:

1) I printed the image sizes of the elements on the left panel and indeed they were the correct sizes from the custom image that I set. So the instance exists, it just does not appear in the view.

2) I tried this in a completely new Xcode project and a user panel button element appeared!

3) Because of this, I tried to create a completely new custom navigation controller in my current project, making it the initial view controller, inserted the above code into my viewDidLoad, but again nothing appeared!

4) I thought that maybe I did something in the App Delegate or the root view of the navigation controller to change the navigation bar. But nothing there at all!

Any ideas? I would appreciate any hints as to why the bur button element will not appear. Thank.

+4
source share
1 answer

, navigationItem, navigationItem . viewDidLoad().

+6

Source: https://habr.com/ru/post/1665134/


All Articles