I have a UINavigationController
into which I push several views. Inside viewDidLoad
for one of these views I want to set the self.navigationI
I would be willing to bet that this is a bug on Apple's part as I am running into the exact same problem. The reason being is that I can get a custom UIBarButtonItem
to appear, but only when I don't try to use the initWithCustomView:
method. Per the API, the navigation controller checks the following things when a new view controller is pushed:
My case (as well as yours) is 2. I specify code exactly the same as yours (i.e., creating a UIButton
, setting its image
properties for various states, creating a UIBarButtonItem
, initializing it with the UIButton
, then setting my current view controller's backBarButtonItem
property to the UIBarButtonItem
); however, when I later push my view controller, nothing at all is displayed on the left-hand side of my navigation controller. Strangely, I can click where the "Back" button should be, and it pops the view controller.
Interestingly, if I create a UIBarButtonItem
using the initWithTitle:style:target:action:
method instead of the initWithCustomView:
method, it does show a custom button with a custom title. Also, as Travis mentioned, using the leftBarButtonItem
property instead works just fine. I'd rather adhere to the sanctioned logic, however, by specifying the "Back" button for the current view controller -- to be displayed later when a new view controller is pushed -- instead of creating a left button for the next view controller, which, arguably, should have no concern for anything pertaining to the view controller that came before it. :-\