Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change RootviewController to Navigation controller

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:

like image 751
Krunal Avatar asked Sep 03 '12 07:09

Krunal


People also ask

How do I add a view controller to my navigation controller?

Step 1: Embed root view controller inside a navigation controller. In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .

How do I get navigation controller from storyboard?

Under the View menu, select Utilities→Show Object Library. In the Object Library, find the Navigation Controller object (see Figure 4-7) and drag and drop it into the storyboard, to the left side of your existing view controller (Figure 4-6). Now you will see something similar to Figure 4-8.

What is a navigation controller?

NavController manages app navigation within a NavHost . Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly. Navigation flows and destinations are determined by the navigation graph owned by the controller.


1 Answers

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.

like image 131
Paresh Navadiya Avatar answered Sep 24 '22 04:09

Paresh Navadiya