如何在没有 xib 的情况下使用 UINavigationController?
我对 Interface Builder 有一种非理性的厌恶。
到目前为止,我得到的只是黑屏。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
PrayViewController* prayViewController = [[PrayViewController alloc] initWithTabBar];
[_window addSubview: [[UINavigationController alloc] initWithRootViewController:prayViewController]];
[prayViewController release];
[self.window makeKeyAndVisible];
return YES;
}
I have an irrational aversion to the Interface Builder.
Here's what I have so far, all I get is the black screen.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
PrayViewController* prayViewController = [[PrayViewController alloc] initWithTabBar];
[_window addSubview: [[UINavigationController alloc] initWithRootViewController:prayViewController]];
[prayViewController release];
[self.window makeKeyAndVisible];
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该向窗口添加一个视图,如下所示:
您将导航视图控制器的整个实例添加到窗口。
UIWindow 是 UIView 的后代,因此它只是继承 addSubview 方法。它需要另一个 UIView 作为参数。
You should add a view to the window, like this:
You are adding the whole instance of the navigation view controller to the window.
UIWindow is a descendant of UIView so it just inherits the addSubview method. It expects another UIView as parameter.
我会检查您的窗口及其视图是否通过 NSLog 返回您所期望的内容。如果没有看到创建窗口及其视图的代码,很难判断,但我怀疑其中之一没有正确创建。
I would check that your window and it view is returning what you expect via NSLog. Without seeing the code that creates the window and its view it is hard to tell but I suspect that one of those is not being created correctly.