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

发布于 2024-09-16 15:51:26 字数 1039 浏览 7 评论 0原文

我正在展示一个用根控制器(即 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];
}

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

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 code 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路黄昏 2024-09-23 15:51:26

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

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

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文