How to add a right NavigationItem to a navigationViewController with root viewController

71 Views Asked by At

I see that UINavigationItem *navigationItem is readonly property of UINavigationViewController.

TestViewController *test = [[TestViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:tableController];
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"Me" style:UIBarButtonItemStyleDone     target:self action:@selector(done:)];
[navigationController.navigationItem setRightBarButtonItem:item]; // NOT WORK


UIPopoverController *pop = [[UIPopoverController alloc]initWithContentViewController:navigationController]; 
pop.popoverContentSize = CGSizeMake(500, 300);
CGRect rect = CGRectMake(300, 400, 50, 50);
[pop presentPopoverFromRect:rect inView:senderButton.superview permittedArrowDirections:0 animated:YES];
1

There are 1 best solutions below

0
On BEST ANSWER

You need to access the navigationItem property of the viewController, not of the navigation controller.

[test.navigationItem setRightBarButtonItem:item]