iPhone UINavigationController 内部 UIViewController [英] iPhone UINavigationController inside UIViewController

查看:22
本文介绍了iPhone UINavigationController 内部 UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

步骤:

  • 列表项
  • 创建一个名为 Nav 的项目.
  • 创建一个新的 UIViewController BaseViewController(带有 XIB)和 FirstViewController(带有 XIB).
  • NavAppDelegat.h中定义baseController变量

  • List item
  • Create a project called Nav.
  • Create a new UIViewController BaseViewController (with XIB) and FirstViewController (with XIB).
  • In the NavAppDelegat.h define baseController variable

@interface NavAppDelegate : NSObject <UIApplicationDelegate> {
BaseViewController *baseController;
}
@property (nonatomic, retain) IBOutlet BaseViewController *baseController; 

  • NavAppDelegat.m 中添加 baseController 到窗口:

  • In the NavAppDelegat.m add baseController to the window:

    @synthesize baseController;
    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [self.window addSubview:baseController.view];
    [self.window makeKeyAndVisible];
    return YES;
    }
    

  • 打开 BaseViewController.xib 文件并添加 UINavigationController,将其根视图控制器类和 XIB 设置为 FirstViewController(在检查器中).

  • Open the BaseViewController.xib file and add UINavigationController, set its Root View Controller class and XIB to FirstViewController (in the inspector).

    我相信这应该向我展示带有导航栏的 FirstViewController.如果我直接在 MainWindow.xib 上执行此操作,事情会按我的预期工作,但在这里我看不到导航栏.我错过了什么?谢谢!

    I believe this should show me the FirstViewController with the navigation bar. If I do this directly on the MainWindow.xib things are working as I expected but here I can't see the navigation bar. What am I missing? THx!

    更新:所以问题是,如果我在一些附加控制器(此处为 BaseViewController.xib)中使用 UINavigationController 而不是 MainWindow.xib,我看不到导航栏.

    UPDATE: So the problem is only that in case I use UINavigationController inside some additional controller (BaseViewController.xib here) instead of MainWindow.xib i don't see the navigation bar.

    推荐答案

    我不知道您是否正在尝试将导航控制器直接连接到您的窗口,只是从第二个 XIB(应该可以工作)或者您正在使您的导航控制器成为另一个视图的子视图,这将不起作用.

    I can't tell if you're trying to connect your navigation controller directly to your window, just from a second XIB (which should work) or if you're making your navigation controller a subview of another view, which won't work.

    UINavigationController 仅用作 UIWindow 的主要子视图或 UITabController 的子视图.Apple 不希望您在其他上下文中嵌入导航控制器.

    UINavigationController is only intended to be used as either the primary subview of a UIWindow or as a subview of a UITabController. Apple doesn't want you embedding a navigation controller in other contexts.

    请参阅组合视图控制器接口查看控制器编程指南了解更多详情.

    See Combined View Controller Interfaces in the View Controller Programming Guide for more details.

    这篇关于iPhone UINavigationController 内部 UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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