开发者

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:pra开发者_StackOverflowyViewController]];
    [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. It expects another UIView as parameter.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜