将 BarButtonItem 添加到模态导航视图控制器
我正在展示一个用根控制器(即 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遇到问题了...正在将 rightBarButtonItem 添加到 navController 的 navigationItem ...我应该将其添加到 viewDidLoad 中 rootViewController 的 navigationItem 中。
Got the problem ... was adding rightBarButtonItem to navController's navigationItem ... I should be adding it to rootViewController's navigationItem in viewDidLoad.