setdirection/ios-shared — pull request #112 by sprynmr (2014-08-07 21:09:20+00:00)
Title: UINavigationBar button handling update

These are the changes necessary for switching to controlling the bar button items more directly. I was only half correct when I said you **have** to pass new copies of a `UIBarButtonItem` for each view controller. It seems in a recent version of iOS, they updated so you can re-use the same button (previously you would get your button vanishing on view controllers if you weren't diligent about removing it before adding it to the new view controller).

However the big caveat would be you only want to do this if there are no changes (additional buttons or buttons changing position) between view controllers. If there are any changes, you'll get janky jumping like we were having with our browse button, and the animation won't work properly (as you need to copies to do a crossfade).

Apple seems to supply a new copy of a `UIBarButtonItem` for every push in their applications, but when they don't change, it's nice to keep them persistent.

Anyway, this is still lets us fix our browse animation bug, and fixes a couple things like not re-setting the global nav when popping (as that view controller already has those controls).

In the case that you need to keep a reference to a button and reuse that, you can obviously store it in a property somewhere. In the case that you are providing new copies on every delegate call (like our browse button will due to animation), you can tag the `UIBarButtonItem` and look it up with this kind of method:

```Objective-C
- (UIBarButtonItem *) barButtonItemWithTag:(NSUInteger) tag {
NSArray *barButtonItems = [[SDPullNavigationManager sharedInstance].globalPullNavController currentVisibleViewController].navigationItem.rightBarButtonItems;
for (UIBarButtonItem *barButton in barButtonItems) {
if (barButton.tag == tag) {
return barButton;
}
}
return nil;
}
```