Cocoa touch 在没有xib的情况下,如何使用UINavigationController?

Cocoa touch 在没有xib的情况下,如何使用UINavigationController?,cocoa-touch,ios,uinavigationcontroller,Cocoa Touch,Ios,Uinavigationcontroller,我对界面生成器有一种非理性的厌恶 这是我到目前为止得到的,我得到的只是黑屏 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the navigation controlle

我对界面生成器有一种非理性的厌恶

这是我到目前为止得到的,我得到的只是黑屏

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

我会检查您的窗口和it视图是否通过NSLog返回您期望的内容。如果看不到创建窗口及其视图的代码,很难说清楚,但我怀疑其中一个没有正确创建。

我会检查您的窗口和it视图是否通过NSLog返回您期望的结果。如果看不到创建窗口及其视图的代码,很难判断,但我怀疑其中一个没有正确创建。

您应该向窗口添加视图,如下所示:

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];
您正在将导航视图控制器的整个实例添加到窗口中


UIWindow是UIView的后代,因此它只是继承了。它需要另一个UIView作为参数。

您应该向窗口添加一个视图,如下所示:

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];
您正在将导航视图控制器的整个实例添加到窗口中

UIWindow是UIView的后代,因此它只是继承了。它需要另一个UIView作为参数