Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

ios - 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.

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.

New setup

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. Perhaps it can come in handy.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For changing the UINavigationBar title (with no need to create 2 other UINavigationController) you can just use

[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.

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

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.

Hope that helps :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...