Question

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:

Was it helpful?

Solution

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.

OTHER TIPS

Instead of:

[self.window addSubview:navigationController.view];

make navigationController the rootViewController of window:

 self.window.rootViewController = navigationController;

Also, is detailViewController of type UINavigationController? You cannot set UINavigationController as root to another UINavigationController object.

Just add this line,

RootViewController *defaultViewController=[[RootViewController alloc]initWithNibName:@"NAME_OF_XIB" bundle:nil];

before UINavigationController's initialization,

RootViewController *defaultViewController=[[RootViewController alloc]initWithNibName:@"NAME_OF_XIB" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
[self.window addSubview:navigationController.view];

[self.window makeKeyAndVisible];
return YES;

Change your RootViewController to NavigationController..

UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.detailViewController];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top