UIViewController 内的 iPhone UINavigationController [英] iPhone UINavigationController inside 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
,将其 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 上执行此操作,则一切正常,但在这里我看不到导航栏.我错过了什么?太好了!
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.
这篇关于UIViewController 内的 iPhone UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!