我看到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];
答案 0 :(得分:1)
您需要访问viewController的navigationItem
属性,而不是导航控制器的属性。
[test.navigationItem setRightBarButtonItem:item]