I received an error when presenting a modal view controller. It says my view controller is detached. Any solution?

101 views Asked by At

Error : "Presenting view controllers on detached view controllers is discouraged ."

HomeView *objHomeView = [[HomeView alloc] initWithNibName:@"HomeView" bundle:nil];
objNav = [[UINavigationController alloc] initWithRootViewController:objHomeView];

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
NSArray *controllers = [NSArray arrayWithObject:objHomeView];
self.sideMenu.navigationController.viewControllers = controllers;
self.window.rootViewController = [self sideMenu].navigationController;
[window makeKeyAndVisible];
1

There are 1 answers

1
Pranay On BEST ANSWER

Change

NSArray *controllers = [NSArray arrayWithObject:objHomeView];

To

NSArray *controllers = [NSArray arrayWithObject:objNav];