title: How to add a UIBarButtonItem programmatically?
body: <p>what's the proper way to add a UIBarButtonItem programmatically? In my case I'm trying to add one to the <code>rightBarButtonItem</code> and I've been hopping round the controller hierarchy but I can't seem to get the button to show up anywhere.</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>- (void)viewDidLoad {
      [super viewDidLoad];
  
      [self.navigationItem setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile:@"Barcode-White.png"] style:UIBarButtonItemStylePlain target:self action:@selector(scanEquipment:)] autorelease]];
  }
  </code></pre>
  
  <p>I'm hoping someone can guide me into the right direction. The controller I'm trying to invoke this from is 3 levels in. So, <code>UITabBarController</code> -> <code>UIViewController (Settings, 1st level)</code> -> <code>UIViewController (Vehicle, 2nd level)</code> -> <code>UIViewController (Inventory, 3rd level)</code>.</p>
  
  <p>Anyway, thanks in advance for any help!</p>