故事板导航控制器和标签栏控制器

Mat*_*ijn 20 storyboard uitabbarcontroller uinavigationcontroller ios uistoryboard

我试图在Storyboard中进行以下设置.

故事板

我在开头有一个表视图,当我点击一个单元格时,它需要转换到标签栏控制器,这是有效的.但是现在我想在最右边的两个控制器中找到一个标题和一个额外的导航栏按钮.

但我似乎无法拖动按钮到那里或设置标题时,没有任何显示.如何在故事板中实现此设置?

编辑:

根据以下答案更新了问题.

新设置

当我有这个新的设置(因此中间有一个额外的导航控制器)我可以在故事板中设置标题,但在运行应用程序时,添加的标题不会显示.

编辑:我已经上传了一个完全符合该设置的xcode项目.也许它可以派上用场.

Eri*_*ann 24

要更改UINavigationBar标题(无需另外创建2个UINavigationController),您可以使用

[self.parentViewController.navigationItem setTitle:@"Title"];
Run Code Online (Sandbox Code Playgroud)

并添加正确的按钮使用

self.parentViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(myRightButton)];
Run Code Online (Sandbox Code Playgroud)

关于viewDidLoad每个UIViewController引用的方法UITabBarController.

如果你想在你的内部使用"导航结构" UIViewController,TabItems那么你可以编辑你的BUFViewController.m:

#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
Run Code Online (Sandbox Code Playgroud)

你必须认为你UITabBarController在父母的内心NavigationController,所以你想要隐藏父母UINavigationBar并展示你的父母.之后,您将能够使用popToRootViewControllerAnimated以下内容返回您的桌面:在父级上UINavigationController.

希望有帮助:)


小智 10

以防任何人都在寻找一个快速的方法:

tabBarController?.title = "Your Title"
tabBarController?.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Right Button Title", style: UIBarButtonItemStyle.Plain, target: self, action: "rightButtonFunction")
Run Code Online (Sandbox Code Playgroud)

该代码最好放在viewDidAppearviewWillAppear这样的标题和按钮变化为不同的选项卡被压.

使用这种方法您也不需要额外的导航控制器.