问题描述
我正在尝试在 Storyboard 中进行以下设置.
I am trying to get the following setup in Storyboard.
一开始我有一个表格视图,当我点击一个单元格时,它需要转换到标签栏控制器,这很有效.但现在我想在最右边的 2 个控制器中添加一个标题和一个额外的导航栏按钮.
Where I have a table view in the beginning, and when I tap a cell it needs to transition to the tab bar controller, which works. But now I want a title and an extra navigation bar button in the the 2 most right controllers.
但我似乎无法将按钮拖到那里,或者在设置标题时,什么也没有显示.如何在情节提要中实现此设置?
But I can't seem to drag a button to there or when setting the title, nothing shows up. How can I achieve this setup in storyboard?
根据以下答案更新问题.
Updated question, based on answer below.
当我有了这个新设置时(因此中间有一个额外的导航控制器),我可以在情节提要中设置标题,但是在运行应用程序时,添加的标题不会显示.
When I have this new setup (thus with an extra navigation controller in between) I can set the title in the storyboard, but when running the app, the added title is not shown.
我已上传一个具有该设置的 Xcode 项目.也许它可以派上用场.
I have uploaded a Xcode project with exactly that setup. Perhaps it can come in handy.
推荐答案
为了改变 UINavigationBar
标题(不需要创建另外 2 个 UINavigationController
)你可以使用
For changing the UINavigationBar
title (with no need to create 2 other UINavigationController
) you can just use
[self.parentViewController.navigationItem setTitle:@"Title"];
添加右键使用
self.parentViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(myRightButton)];
关于从 UITabBarController
引用的每个 UIViewController
的 viewDidLoad
方法.
on viewDidLoad
method for each UIViewController
referenced from your UITabBarController
.
如果您想在 TabItems
的 UIViewController
中使用导航结构",则可以将 BUFViewController.m 编辑为:
If you want to work with "navigation structures" inside your UIViewController
from TabItems
so you could edit your BUFViewController.m to that:
#import "BUFViewController.h"
@interface BUFViewController ()
@end
@implementation BUFViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.parentViewController.navigationController setNavigationBarHidden:YES];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
}
-(void)done{
[self.parentViewController.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
你必须认为你的 UITabBarController
在你的父 NavigationController
中,所以你想隐藏父 UINavigationBar
并显示你的.之后,您将能够在父级的 UINavigationController
上使用 popToRootViewControllerAnimated
: 返回您的表.
You have to think as your UITabBarController
is inside your parent NavigationController
, so you want to hide the parent UINavigationBar
and show yours.
After that, you'll be able to back to your table using popToRootViewControllerAnimated
: on the parent's UINavigationController
.
希望有帮助:)
这篇关于故事板导航控制器和标签栏控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!