如何使用root viewController将正确的NavigationItem添加到navigationViewController

时间:2014-11-11 00:46:34

标签: ios ios7 uinavigationbar uinavigationitem

我看到UINavigationItem * navigationItem是UINavigationViewController的readonly属性。

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 个答案:

答案 0 :(得分:1)

您需要访问viewController的navigationItem属性,而不是导航控制器的属性。

[test.navigationItem setRightBarButtonItem:item]