UIViewController中的iPhone UINavigationController [英] iPhone UINavigationController inside UIViewController

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

问题描述

步骤:


  • 列表项

  • 创建一个名为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 ,将其Root View Controller类和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上执行此操作,我的工作正常,但在这里我看不到导航栏。我错过了什么? THx!

    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!

    更新:
    所以问题只是在我使用 UINavigationController 的情况下控制器(这里是BaseViewController.xib)而不是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.

    参见组合视图控制器接口

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

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