简体   繁体   English

我如何在没有xib的情况下使用UINavigationController?

[英]How do I use the UINavigationController without a xib?

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;
}

You should add a view to the window, like this: 您应该向窗口添加视图,如下所示:

UIViewController *rootController = [[MyRootViewController alloc] init];
navigationController = [[UINavigationController alloc]
                            initWithRootViewController:rootController];
[rootController release];

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// *** IMPORTANT DIFFERENCE:
[window addSubview:navigationController.view];

[window makeKeyAndVisible];

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 . UIWindow是UIView的后代,因此它仅继承addSubview方法 It expects another UIView as parameter. 它期望另一个UIView作为参数。

I would check that your window and it view is returning what you expect via NSLog. 我将检查您的窗口和它的视图是否通过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. 没有看到创建窗口及其视图的代码,很难说,但是我怀疑其中之一没有正确创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将UITabBarController子视图添加到UINavigationController - How do I add UITabBarController subview to UINavigationController 我需要 UINavigationController 吗? - Do I need a UINavigationController? 如何在UINavigationController中使用UIViewControllerAnimatedTransitioning? - How to use UIViewControllerAnimatedTransitioning with UINavigationController? 如何添加到UINavigationController推送动画,而不是替换它? - How do I add to a UINavigationController push animation, rather than replace it? 如何在实例化的Storyboard中将数据传递到UINavigationController的rootViewController? - How do I pass data to a rootViewController of a UINavigationController in an instantiated Storyboard? 如何创建具有默认“后退”状态的UINavigationController? - How do I create a UINavigationController with a default “back” state? 在 iOS 7 中推送 UINavigationController 上的视图时如何交叉溶解? - How do I cross dissolve when pushing views on a UINavigationController in iOS 7? 如何初始化UINavigationController呈现的自定义视图? - How do I initialize a custom view that is presented by UINavigationController? 如何在ipad上的方向更改上加载新的xib? - How do i load a new xib on an orientation change on the ipad? 如何使用自己的UIViewController创建可重用的XIB? - How do I make a reusable XIB with it's own UIViewController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM