我在根视图中使用SWRevealViewController
并使用自定义类中的两个按钮创建自定义静态视图。
如果我单击按钮 - 从自定义自定义类
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类型的未捕获异常终止
答案 0 :(得分:1)
您错误的是nested
UINavigationController
,因为建议在嵌套时不要使用多个UINavigationController 。
只需使用UIViewController
,而不是UINavigationcontroller
上使用UINavigationcontroller
答案 1 :(得分:0)
我不确定你的问题是什么,但这是我使用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)
答案 2 :(得分:0)
问题是您正在尝试将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];