我有一个UINavigationController.我正在尝试在navigationBar的右侧添加多个按钮.我怎样才能做到这一点?需要什么样的按钮?UIBarButton还是UINavigationItem?
在我的应用程序中,我有一个带有 UINavigationControllers 初始化的 UITabBarControllers
UINavigationController *newsNavigationController = [[UINavigationController alloc] initWithRootViewController: newsViewControler];
Run Code Online (Sandbox Code Playgroud)
newsViewController 是一个 UIViewController。当我按下标签栏中的按钮以显示带有 newsViewController 的导航项时,导航栏中的标题设置正常。在 newsViewController 我有一个方法设置,我在初始化之后调用。在设置方法中,我设置了这样的标题
[[self navigationItem] setTitle:[category_c title]];
现在问题来了,在我的 newsViewController 中,我有一个 tableView,当我触摸一个单元格时,我想推送一个带有所选新闻的 UIViewController 并在导航栏中显示标题。
在 UIViewController 我有相同的设置方法,我在上面设置标题。问题是没有显示。导航项不为空,因为我可以调用self.navigationItem.hidesBackButton = YES;并且每次都隐藏后退按钮但未显示标题。
当触摸单元格时,我像这样创建并推送新闻 UIViewController
if(newsViewController == nil){
newsViewController = [[NewsViewController alloc] init];
[newsViewController setup];
}
[self.navigationController pushViewController: newsViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
newsViewController 中的设置方法如下所示:
- (void) setup {
self.navigationItem.hidesBackButton = YES;
[self.navigationItem setTitle:@"my view"];
}
Run Code Online (Sandbox Code Playgroud)
在 newsViewController 我有 viewDidLoad 并试图在那里设置标题但没有成功。
如果在[self.navigationController pushViewController: …