Adding BarButtonItem to a Modal Navigation View Controller
I am presenting a modal navigation bar controller initialized with a root controller (which is a UITableViewController). When I, initialize the UINavigationBarController to present it modally, I am also adding a "Submit" button as a right bar button item. Everything is working fine (loading with root view and Modal presentation) However, the right button is not showing. Posting the c开发者_开发技巧ode below -
-(IBAction) presentAddLeaveRequestModally {
AddLeaveRequestViewController *leaveRequestViewController = [[AddLeaveRequestViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:leaveRequestViewController];
UIBarButtonItem *submitButton = [[UIBarButtonItem alloc] initWithTitle:@"Submit"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(submitLeaveRequest)];
navController.navigationItem.rightBarButtonItem = submitButton;
[self.homeTabBarController presentModalViewController:navController animated:YES];
}
Any ideas if I am missing something obvious?
Got the problem ... was adding rightBarButtonItem to navController's navigationItem ... I should be adding it to rootViewController's navigationItem in viewDidLoad.
UIBarButtonItem *submitButton = [[UIBarButtonItem alloc] initWithTitle:@"Submit"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(submitLeaveRequest)];
self.navigationItem.rightBarButtonItem = submitButton;
精彩评论