title: Add image to UIBarButtonItem button
body: <p>I have added UITabButtonItem onto my view controller using following code. Could anyone please tell me if its possible to associate image with it?</p>
  
  <pre><code>UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(favouriteButtonClicked:)]; 
  viewController2.navigationItem.rightBarButtonItem = button; 
  [button release];
  [self.navigationController pushViewController:viewController2 animated:YES];
  </code></pre>
  
  <p>I use following code at other places but as in above code I am pushing viewcontroller onto my current view, this code doesn't work. I had to use above code.</p>
  
  <pre><code>UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
  [button setImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
  [button addTarget:self action:@selector(favouriteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  [button setFrame:CGRectMake(280, 25, 30, 30)];
  viewController2.navigationController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
  
  [self.navigationController pushViewController:viewController2 animated:YES];
  </code></pre>
  
  <p>I don't know what is wrong but when I replace this custom button code with initWithBarButtonSystemItem, it works fine!!!</p>
  
  <p>Finally I sorted out this issue and posted working code here but still I don't understand if I have a button in baseviewcontroller and I add it like following, it doesn't work!!! I had to use the code given in my accepted answer in viewwillappear!!</p>
  
  <pre><code>    [favButton addTarget:self action:@selector(favouriteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
       self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];  
  </code></pre>
  
  <p>Following code still doesn't work!!! Don't know what's going on.</p>
  
  <pre><code>MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:filePath]] autorelease];
  
  UIButton* favouritebutton =  [UIButton buttonWithType:UIButtonTypeCustom];
  [favouritebutton setBackgroundImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
  [favouritebutton addTarget:self action:@selector(favouriteButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  [favouritebutton setFrame:CGRectMake(280, 25, 30, 30)];
  videoController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:favouritebutton] autorelease]; 
  
  [self presentMoviePlayerViewControllerAnimated:videoController];
  </code></pre>
  
  <p>Thanks.</p>