将两个导航控制器添加到一个选项卡项目 [英] add two navigation controller to one Tab bar Item

查看:195
本文介绍了将两个导航控制器添加到一个选项卡项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要2个导航控制器附加到一个选项卡栏项目。

I want 2 navigation Controller to be attached to one Tab bar item.

基本上,想法是在单个选项卡项目有2个视图,导航栏推动和弹出屏幕。 (类似iPad中的设置应用程序)。

Basically the idea is to have 2 views on a single tab Item and there should be a navigation bar to push and pop the screens. (same like settings application in iPad).

编辑======

在左侧有一个View有自己的导航控制器和右侧有另一个View用自己的导航控制器(或一些其他UI)实现Push Pop的东西。

It will look like on left hand side there is a View with its own navigation Controller and on right hand side there is another View with its own navigation controller(or some other UI) to achieve the Push Pop stuff.

我知道如何将1个导航控制器附加到一个标签栏项目。

I know how to attach 1 navigation Controller to one Tab bar Item.

已针对ModalView问题编辑: -
通过实施conmulligan代码一切正常的属性。但是如果我试图显示一些ModalViewController在lansdscape模式,当我尝试关闭这个ModalView的FirstViewController导航栏变成肖像(连同其View)和SecondViewController NavigationBar仍然是景观(应该是)。这只发生在设备不在模拟器。

Edited For ModalView Issue:- by implementing conmulligan code everything works property. But if I try to display some ModalViewController in lansdscape mode and when I try to close this ModalView the FirstViewController navigationbar becomes portrait(along with its View) and SecondViewController NavigationBar remains landscape(at it should be). This happens only in Device not in simulator.

以下是介绍ModalViewController的代码。

Below is my Code of presenting the ModalViewController.

ModalTableViewController *modalTableViewController = [[ModalTableViewController alloc]initWithNibName:@"ModalTableViewController" bundle:[NSBundle mainBundle]]; 
UINavigationController *localNavigationViewController = [[UINavigationController alloc] initWithRootViewController:modalTableViewController];
localNavigationViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:localNavigationViewController animated:YES];
[modalTableViewController release];
[localNavigationViewController release];

要关闭ModalViewCntroller,请执行以下操作: -

For Dismising the ModalViewCntroller I do it as below:-

[self dismissModalViewControllerAnimated:YES]; 

正在等待您的回复。

推荐答案

一种方法是创建 UIViewController 包含两个导航控制器的子类,并将其添加到 UITabBarController 。以下是如何在 UIViewController -viewDidLoad 方法中创建和布局导航控制器:

One way would be to create a UIViewController subclass that contains two navigation controllers and add that to the UITabBarController. Here's how you'd create and layout the navigation controllers in the UIViewController's -viewDidLoad method:

FirstViewController *firstViewController = [[FirstViewController alloc] init];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];

SecondViewController *secondViewController = [[SecondViewController alloc] init];
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];

firstNavigationController.view.frame = CGRectMake(0.f, 0.f, 320.f, self.view.frame.size.height);
firstNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;

secondNavigationController.view.frame = CGRectMake(321.f, 0.f, self.view.frame.size.width - 321.f, self.view.frame.size.height);
secondNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |
                                                   UIViewAutoresizingFlexibleRightMargin;

[self.view addSubview:firstNavigationController.view];
[self.view addSubview:secondNavigationController.view];

这或多或少是 UISplitViewController

编辑:您可能需要添加以下代码,以确保其正确布局:

you might need to add the following code to make sure it lays out properly:

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated];
    [firstNavigationController viewWillAppear:animated];
    [secondNavigationController viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated];
    [firstNavigationController viewWillDisappear:animated];
    [secondNavigationController viewWillDisappear:animated];
}

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated];
    [firstNavigationController viewDidAppear:animated];
    [secondNavigationController viewDidAppear:animated];
}

- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated];
    [firstNavigationController viewDidDisappear:animated];
    [secondNavigationController viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

这篇关于将两个导航控制器添加到一个选项卡项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆