change RootviewController to Navigation controller

Krunal picture Krunal · Sep 3, 2012 · Viewed 14.3k times · Source

I am new to iPhone,

I want to change my Rootviewcontroller to my new class and make it to navigation controller.

Here is my code snippet,

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


    UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
    [self.window addSubview:navigationController.view];

    [self.window makeKeyAndVisible];


    return YES;
}

I am getting SIGABRT says 'adding a root view controller <NewClass: 0x6a8dd50> as a child of view controller:

Answer

Paresh Navadiya picture Paresh Navadiya · Sep 3, 2012

Whenever u want to set:

DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
self.window.rootViewController =nil;
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];

EDIT : Directly use AppDelegate instance to set rootViewController for UIWindow as i have shown above.