I am trying to place an icon on the right of a navigation bar throughout my app. This is everywhere but the home screen (though it would be fine there as well, since I hide it on that view controller): the table view controller at the top, and the map view and table view controllers on the far right of the image below.
This code mysteriously works to set the icon in the center of the navigation bar on one view controller (Favorites view controller, top left), which is a tableview controller, segued from a UIViewController that is embedded in a navigation controller:
let yelpIcon = UIBarButtonItem(image: UIImage(named: "Yelp_trademark_RGB_outline"), style: .plain, target: self, action: nil)
self.navigationController!.navigationItem.rightBarButtonItem = yelpIcon
My Map and TableViewControllers (far right) are embedded in navigation controllers, that are each embedded in a tab bar controller. I cannot get the image to show up by creating a navigation item in Interface Builder and setting its image, or by doing it programmatically.
This code is recommended highly on SO, but has no result when I try it (I have action set to nil, since I don't need it to do anything):
let button1 = UIBarButtonItem(image: UIImage(named: "myimage"), style: .plain, target: self, action: Selector("action"))
self.navigationItem.rightBarButtonItem = button1
Note: Nav bar is stylized with black barTintColor, which shouldn't make a difference but I thought I'd share. Image is a PNG in my assets folder. In using the debug view hierarchy, I came across these two layers that appear to be blocking my image from appearing (though they don't do this with the back button).
Instance address 0x7fa8b7b10aa0 is a UIVisualEffectSubView. I'm not sure if this is the issue, but I can't figure out how to turn it off either. I have changed the view tint color in the navigation bar on the navigation controller in which it is embedded to transparent, as well as turning off opacity. Neither worked.
How can I get the image on the right of my nav bar to appear?