开发者

Adding BarButtonItem to a Modal Navigation View Controller

开发者 https://www.devze.com 2023-01-13 16:45 出处:网络
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 al

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消