将BarButtonItem添加到模态导航视图控制器

时间:2010-08-31 12:17:30

标签: uinavigationcontroller uibarbuttonitem modalviewcontroller

我提出了一个用根控制器初始化的模态导航栏控制器(它是一个UITableViewController)。当我初始化UINavigationBarController以模态方式呈现它时,我还添加了一个“提交”按钮作为右键按钮项。一切正常(使用根视图和模态演示加载)但是,右键没有显示。 发布以下代码 -

-(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];
}

如果我遗漏了一些明显的东西,那还有什么想法?

1 个答案:

答案 0 :(得分:8)

遇到问题...正在将rightBarButtonItem添加到navController的navigationItem ...我应该将它添加到viewDidLoad中的rootViewController的navigationItem。

UIBarButtonItem *submitButton = [[UIBarButtonItem alloc] initWithTitle:@"Submit" 
                                                                 style:UIBarButtonItemStyleBordered
                                                                 target:self 
                                                                 action:@selector(submitLeaveRequest)];
self.navigationItem.rightBarButtonItem = submitButton;