【问题标题】:push view error in SWRevealViewControllerSWRevealViewController 中的推送视图错误
【发布时间】:2015-06-26 20:11:00
【问题描述】:

我在根视图中使用SWRevealViewController,并在自定义类中使用两个按钮制作自定义静态视图。
如果我单击按钮 - 从自定义自定义类推送 nextView 控制器

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];

但是推送后看到的错误如下:

由于未捕获的异常“UIViewControllerHierarchyInconsistency”而终止应用程序,原因:“添加根视图控制器 SWRevealViewController:0x137629e60 作为视图控制器的子级:UINavigationController:0x137658b50” *** 首先抛出调用堆栈: (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:以 NSException 类型的未捕获异常终止

【问题讨论】:

  • 我认为问题在于您正在尝试推送navigationController'. Try pushing directly on the SWRevealViewController`
  • 你能展示你的故事板序列吗

标签: ios objective-c uinavigationcontroller swrevealviewcontroller


【解决方案1】:

问题是您试图将UINavigationController 实例推送到UINavigationController 的另一个实例中。这会产生UIViewController 层次结构的内部不一致。试试这个:

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];

【讨论】:

    【解决方案2】:

    你犯的错误是nestedUINavigationController,因为它建议嵌套时不要使用多个 UINavigationController

    所以只需使用您的UIViewController 而不是在UINavigationcontroller 上使用UINavigationcontroller

    【讨论】:

      【解决方案3】:

      我不确定你的问题是什么,但这是我使用 swift 的版本,它可以工作。

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

      如果你只是想从另一个视图控制器中推入一个视图控制器,这里是如何做到的:

          var newProfileVC = ProfileVC()
          newProfileVC.mainVCPointer = self
          navigationController?.pushViewController(newProfileVC, animated: true)
      

      【讨论】:

        猜你喜欢
        • 2015-11-13
        • 2014-11-23
        • 2016-03-06
        • 2016-06-20
        • 2015-09-07
        • 1970-01-01
        • 2014-06-30
        • 2015-08-16
        • 2017-05-30
        相关资源
        最近更新 更多