0

I'm trying to add a rightBarButtonItem to the navigationitem.But whatever I do I can not see the button on the navigation bar. If I NSLog for self.navigationItem.title I get the right title.And also if I NSLog the rightBarButtonItem I get the barbutton item's memory locatioin, so not null. Here's how I add my bar button item:

UIBarButtonItem *barButton= [[UIBarButtonItem alloc] initWithTitle:......];
self.navigationItem.rightBarButtonItem=barButton;

What should I do to make the button visible on the navigation bar.

EDIT: Here's the ViewCOntroller hierarchy:

MechViewController//This gets pushed to the navigation stack

PageViewController//This is created in the MechViewController viewDidLoad method and added as a childViewController

PhotoViewController//This is view controller that I add to the PageViewController's viewControllers array. This is where I need to add bar button item and specify its action.

Mikayil Abdullayev
  • 12,117
  • 26
  • 122
  • 206
  • WHat do you by screens? This is the only part of the code that involves adding a bar button item. – Mikayil Abdullayev May 19 '12 at 19:41
  • And also, I tried adding the above code right after pushing the view controller to the navigation stack and I got the button displayed. But I need to do it on a child view controller. – Mikayil Abdullayev May 19 '12 at 19:43
  • When you creating `PhotoViewController`-instance in `PageViewController`, try to write `instance.navigationItem.rightBarButtonItem = ...` – demon9733 May 20 '12 at 07:07

1 Answers1

0

You should add the button in viewDidLoad.

- (void)viewDidLoad {
  [super viewDidLoad];

  IBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:......];
  self.navigationItem.rightBarButtonItem = barButton;
  [barButton release];
}
cellcortex
  • 3,166
  • 1
  • 24
  • 34