情节提要导航控制器和选项卡栏控制器

情节提要导航控制器和选项卡栏控制器

本文介绍了情节提要导航控制器和选项卡栏控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在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引用的每个UIViewControllerviewDidLoad方法上

.

on viewDidLoad method for each UIViewController referenced from your UITabBarController.

如果要在UIViewController中使用TabItems中的导航结构",则可以将 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并显示您的父级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.

希望有帮助:)

这篇关于情节提要导航控制器和选项卡栏控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 23:11