将导航控制器添加到UIViewController [英] add a Navigation controller to a UIViewController

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

问题描述

我刚刚完成了有关如何从基于窗口的应用程序项目开始创建导航控制器的教程.

I've just worked through a tutorial on how to create a Navigation controller starting with a Window-Based application project.

现在,我正在尝试找出如何将本教程中使用的方法与具有标签栏控制器的根视图一起应用.

Now, I'm trying to figure out how to applied the methods I used in the tutorial with a root view that has a tab bar controller.

我再次使用基于窗口的应用程序项目设置了标签栏控制器,并添加了四个标签栏项目,这些项目分别链接到各自的UIViewController类/笔尖.

I've set up a tab bar controller, again using the window-based app project, and added four tab bar items that are linked to their respective UIViewController classes/nib.

是否可以像在基于窗口的教程中那样将导航控制器添加到UIViewController类中?

Can I add a nav controller like I did with my window-based tutorial to the UIViewController classes?

这是我自己创建导航控制器的方式:

Here is how i created a nav controller by itself:

#import <UIKit/UIKit.h>

@interface NavAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UINavigationController *navController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

@end




#import "NavAppDelegate.h"

@implementation NavAppDelegate

@synthesize window;
@synthesize navController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    [self.window addSubview:navController.view];
    [window makeKeyAndVisible];

    return YES;
}



etc...

推荐答案

UINavigationControllerUITabBarController都是控制器的控制器,即它们管理多个UIViewControllers. UIViewControllers依次管理视图.因此,您的问题的标题确实需要修改.

Both UINavigationController and UITabBarController are controllers of controllers, i.e. they manage multiple UIViewControllers. The UIViewControllers in turn manage the views. So the title of your question does need revision.

标准设置是这样的:UITabBarController是根控制器.每个选项卡控制 UIViewController UINavigationController,后者依次管理UIViewControllers.

The standard setup is this: UITabBarController is the root controller. Each tab controls either a UIViewController or a UINavigationController which in turn manages UIViewControllers.

因此,您将UIViewControllersUINavigationControllers添加到标签栏项.

So you add UIViewControllers or UINavigationControllers to your tab bar items.

因此,您的问题的直接答案是:.您不能向您的UIViewController添加UINavigationController,反之亦然.

Thus, the direct answer to your question is: no. You cannot add a UINavigationController to your UIViewControllerbut rather the other way round.

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

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