0

我正在尝试将 UINavigationController 添加到我的 ViewController。当我启动应用程序时,它只给我一个黑屏并且不启动应用程序。

这是我的 AppDelegate.m :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

UIViewController *rootView = [[ViewController alloc]
                              initWithNibName:@"ViewController"
                              bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:rootView];
[[self window] setRootViewController:self.navController];

//template code
[self.window makeKeyAndVisible];
[rootView release];
return YES;

}

我正在关注这篇文章:http ://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/

怎么了?谢谢!

4

2 回答 2

1

尝试使用 ARC 和故事板 如果您的目标是 IOS 5+,这会容易得多,您甚至需要编写代码,只需将导航控制器拖放到故事板即可。

没有测试,但试试这个:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

UIViewController *rootView = [[ViewController alloc]
                              initWithNibName:@"ViewController"
                              bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:rootView];
        self.window.rootViewController =nil;
        self.window.rootViewController = navigationController;
        [self.window makeKeyAndVisible];
return YES;

}
于 2013-05-15T17:07:59.740 回答
0

只是用一个项目测试并使用这个代码......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[CCViewController alloc] initWithNibName:@"CCViewController" bundle:nil];
    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = navControl;
    [self.window makeKeyAndVisible];
    return YES;
}

工作得很好。

于 2013-05-15T17:09:42.653 回答