Reputation: 6490
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:
Upvotes: 6
Views: 14484
Reputation: 38239
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.
Upvotes: 13
Reputation: 3508
Change your RootViewController to NavigationController..
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.detailViewController];
Upvotes: 0
Reputation: 1028
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;
Upvotes: 1
Reputation: 7644
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.
Upvotes: 2