0

I use SWRevealViewController in root view and make custom static view with two button in custom class.
If I click button - push nextView controller from custom custom class

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

UINavigationController *navigationController = [storyBoard instantiateViewControllerWithIdentifier:@"historyGoodsView"];

SWRevealViewController *rootViewController = (SWRevealViewController *)[[[UIApplication sharedApplication] keyWindow]rootViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

[navController pushViewController:navigationController animated:true];

But after pushed the error seen is given below:

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'adding a root view controller SWRevealViewController: 0x137629e60 as a child of view controller:UINavigationController: 0x137658b50' *** First throw call stack: (0x1844bc2d8 0x195ce00e4 0x1844bc218 0x188f976c0 0x188f975b0 0x188f8cb00 0x188f8c700 0x188fea070 0x1000e39d8 0x188f31404 0x188f1a4e0 0x188f30da0 0x188f30a2c 0x188f29f68 0x188efd18c 0x18919e324 0x188efb6a0 0x184474240 0x1844734e4 0x184471594 0x18439d2d4 0x18dbb36fc 0x188f62fac 0x100108218 0x19635ea08) libc++abi.dylib: terminating with uncaught exception of type NSException

Chirag Shah
  • 3,034
  • 1
  • 30
  • 61
alex willrock
  • 986
  • 3
  • 9
  • 22

3 Answers3

1

You made mistake is nested UINavigationController as its recommended not to use more than a single UINavigationController while nesting.

So simply use your UIViewController only rather than using UINavigationcontroller on UINavigationcontroller

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
0

I am not sure what your problem is but here is the version I am using with swift and it works.

    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    let viewController = StartVC()
    let navigationController = UINavigationController(rootViewController: viewController)
    window?.rootViewController = navigationController

    self.window?.makeKeyAndVisible()

If you just want to push a view controller in from another view controller, here is how to do it:

    var newProfileVC = ProfileVC()
    newProfileVC.mainVCPointer = self
    navigationController?.pushViewController(newProfileVC, animated: true)
Esqarrouth
  • 38,543
  • 21
  • 161
  • 168
0

The problem is you are trying to push a UINavigationController instance into another instance of UINavigationController. This generates an internal inconsistency of the UIViewController hierarchy. Try this:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

UIViewController *yourNextViewController = (UIViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"historyGoodsView"];

SWRevealViewController *rootViewController = (SWRevealViewController *)[[[UIApplication sharedApplication] keyWindow]rootViewController];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

[navController pushViewController:yourNextViewController animated:YES];
flizana
  • 569
  • 6
  • 26