iPhone UIViewController 内的 UINavigationController
步骤:
- 列表项
- 创建一个名为 Nav 的项目。
- 创建一个新的
UIViewController
BaseViewController(使用 XIB)和 FirstViewController(使用 XIB)。 在
NavAppDelegat.h
中定义baseController变量@interface NavAppDelegate : NSObject
; { BaseViewController *baseController; } @property(非原子,保留)IBOutlet BaseViewController *baseController; 在
NavAppDelegat.m
中将baseController添加到窗口:@synthesize baseController; (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self.window addSubview:baseController.view]; [self.window makeKeyAndVisible]; 返回是; }
打开BaseViewController.xib文件并添加
UINavigationController
,设置其Root View控制器类和 XIB 到 FirstViewController(在检查器中)。- 还将 navigationController 变量与 UINavigationController 连接起来。
我相信这应该向我显示带有导航栏的 FirstViewController 。如果我直接在 MainWindow.xib 上执行此操作,事情就会按我的预期工作,但在这里我看不到导航栏。我缺少什么?谢谢!
更新: 所以问题只是,如果我在一些附加控制器(此处为 BaseViewController.xib)而不是 MainWindow.xib 中使用 UINavigationController
,我看不到导航栏。
Steps:
- 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;
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; }
Open the BaseViewController.xib file and add
UINavigationController
, set its Root View Controller class and XIB to FirstViewController (in the inspector).- Also connect navigationController variable with the
UINavigationController
.
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!
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法判断您是否正在尝试将导航控制器直接连接到您的窗口,只是从第二个 XIB (应该可以工作),或者您是否正在使导航控制器成为另一个视图的子视图,这将无法工作。
UINavigationController
仅用作UIWindow
的主子视图或UITabController
的子视图。 Apple 不希望您在其他环境中嵌入导航控制器。请参阅视图控制器编程中的组合视图控制器接口指南了解更多详情。
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
is only intended to be used as either the primary subview of aUIWindow
or as a subview of aUITabController
. 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.