简体   繁体   English

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

[英]Storyboard navigation controller and tab bar controller

I am trying to get the following setup in Storyboard.我正在尝试在 Storyboard 中进行以下设置。

故事板

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.但现在我想要一个标题和一个额外的导航栏按钮在 2 个最右边的控制器中。

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

I have uploaded a Xcode project with exactly that setup.我已经上传了一个具有该设置的 Xcode 项目。 Perhaps it can come in handy.也许它可以派上用场。

For changing the UINavigationBar title (with no need to create 2 other UINavigationController ) you can just use要更改UINavigationBar标题(无需创建 2 个其他UINavigationController ),您只需使用

[self.parentViewController.navigationItem setTitle:@"Title"];

and for adding the right button use并添加右键使用

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

on viewDidLoad method for each UIViewController referenced from your UITabBarController .在从您的UITabBarController引用的每个UIViewController viewDidLoad方法上。

If you want to work with "navigation structures" inside your UIViewController from TabItems so you could edit your BUFViewController.m to that:如果您想在TabItemsUIViewController使用“导航结构”,则可以将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

You have to think as your UITabBarController is inside your parent NavigationController , so you want to hide the parent UINavigationBar and show yours.您必须考虑到您的UITabBarController在您的父NavigationController ,因此您想隐藏父UINavigationBar并显示您的。 After that, you'll be able to back to your table using popToRootViewControllerAnimated : on the parent's UINavigationController .之后,您将能够使用popToRootViewControllerAnimated返回到您的表:在父级的UINavigationController

Hope that helps :)希望有帮助:)

Just in case anyone was looking for a swift approach:以防万一有人正在寻找一种快速的方法:

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

The code is best placed in viewDidAppear or viewWillAppear so the title and button change as the different tabs are pressed.代码最好放在viewDidAppearviewWillAppear这样标题和按钮会随着不同的选项卡被按下而改变。

You also wouldn't need the extra navigation controllers with this approach.通过这种方法,您也不需要额外的导航控制器。

I looked at your test app, and I do see the title, very faintly, under the navigation bar.我看了你的测试应用程序,我确实在导航栏下看到了标题,非常模糊。 You can see both navigation bars if you select the tab bar controller, and uncheck the "Under Top Bars" box.如果您选择标签栏控制器,并取消选中“在顶部栏下”框,您可以看到两个导航栏。 However, this gives you a weird shadow on the navigation bar.但是,这会在导航栏上给您一个奇怪的阴影。 I don't know if there's an easy way to fix this, but I don't think this UI with two navigation bars looks good any way.我不知道是否有一种简单的方法可以解决这个问题,但我认为这个带有两个导航栏的 UI 无论如何都不好看。 You might want to eliminate the initial navigation controller, and use a modal segue to present the tab bar controller instead.您可能希望消除初始导航控制器,而使用模态转场来显示标签栏控制器。 You could add a bar button item to the navigation controllers you still would have to do the dismissal of the modal view controller.您可以向导航控制器添加一个条形按钮项,您仍然需要关闭模态视图控制器。

You need to replace those view controllers with UINavigationViewControllers .您需要用UINavigationViewControllers替换这些视图控制器。

Delete the right two view controllers.删除右边的两个视图控制器。

Drag drop 2 UINavigationViewControllers onto the storyboard and position them how you want.将 2 个UINavigationViewControllers拖放到情节UINavigationViewControllers上并按照您的需要放置它们。

Then, you need to hook those new navigation view controllers to the tab bar controller.然后,您需要将这些新的导航视图控制器挂钩到选项卡栏控制器。 Ctrl click and drag from the tab bar controller to the navigation controllers. Ctrl 单击并从选项卡栏控制器拖动到导航控制器。 Select "view controllers" from the "Relationship Segue" section of the menu that pops up.从弹出菜单的“Relationship Segue”部分选择“view controllers”。 Do this for both navigation controllers.对两个导航控制器执行此操作。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"Overview_Register"])
    {
        WDRegisterViewController *obj=(WDRegisterViewController *)[segue destinationViewController];
        obj.str_Title=@"Edit Profile";
        obj.isRegister=NO;
    }
}

            [self performSegueWithIdentifier:@"Overview_Measure" sender:nil];



    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    WDPeekViewController *Peek = (WDPeekViewController *)[sb instantiateViewControllerWithIdentifier:@"WDPeekViewController"];
 [self.navigationController pushViewController:tabBarController animated:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置情节提要选项卡控制器,更多选项卡的导航栏颜色 - Setting a Storyboard Tab Controller, More Tab's Navigation Bar Colour 具有导航控制器的标签栏控制器的导航控制器 - Navigation controller with tab bar controller of navigation controller 如何在故事板的标签栏上启动导航控制器的第三个视图控制器 - how to start third view controller of navigation controllers on tab bar in storyboard 导航控制器到选项卡栏控制器 - Navigation controller to tab bar controller 带标签栏控制器的导航控制器? - Navigation controller with tab bar controller? 导航 Controller 和标签栏 Controller - Navigation Controller and Tab Bar Controller 根据故事板中导航控制器的不同按钮调用相同标签栏控制器的特定选项卡 - Calling particular tabs of same tab bar controller based on different buttons from navigation controller in storyboard 如何在Main.storyboard中具有参考的其他Storyboard中为导航控制器设置选项卡图标和标题? - How to set tab bar icon and title for a Navigation controller in different Storyboard which has reference in Main.storyboard? 将标签栏添加到导航控制器 - Add Tab Bar to Navigation Controller 标签栏控制器中的导航控制器 - Navigation Controllers in tab bar controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM