Search code examples
iosios8uibarbuttonitemuinavigationitem

Assignment to leftBarButtonItem has no effect after first time


I am setting up an "Edit" / "Done" button as follows:

self.navigationItem.leftBarButtonItem = self.editButtonItem;

This works the first time around (from within viewWillAppear:) but not on subsequent occasions (after an UISegmentedControl changed its value) and after having set self.navigationItem.leftBarButtonItem to nil in between. I have confirmed that all such assignments occur on the main thread.

Am I supposed to explicitly force an update of the navigation bar in the UI (with an equivalent of setNeedsDisplay) or what else could go wrong here?


Solution

  • Using this call instead resolves the issue, although I am not yet sure how.

    [self.navigationItem setLeftBarButtonItem: self.editButtonItem animated: YES];
    

    I'd still appreciate an answer as to how.