我正面临以下代码的崩溃。场景是
这是我使用 UINavigationController 加载 RTC_HomeVC 的应用程序委托方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
RTC_HomeVC *obj_RTC_HomeVC=[[RTC_HomeVC alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:obj_RTC_HomeVC];
// Override point for customization after application launch.
self.window.rootViewController=nav;
[obj_RTC_HomeVC release];
[nav release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
现在我想在父导航控制器中打开 UINavigationController。所以我使用以下代码。方法 -(IBAction)call_SectionFlow 在 RTC_HomeVC 中。
-(IBAction)call_SectionFlow{
RTC_1_StoreDetailsVC *obj_StoreDetailsVC=[[RTC_1_StoreDetailsVC alloc]initWithNibName:@"RTC_1_StoreDetailsVC" bundle:nil];
RTC_3_EnablingWorksVC *obj_EnablingWorksVC = [[RTC_3_EnablingWorksVC alloc]initWithNibName:@"RTC_3_EnablingWorksVC" bundle:nil];
UINavigationController *navController_Sections = [[UINavigationController alloc] init];
NSArray *array_ControllerArray=[[NSArray alloc]initWithObjects:obj_StoreDetailsVC,obj_EnablingWorksVC, nil];
[navController_Sections setViewControllers:array_ControllerArray animated:FALSE]
navController_Sections.view.frame=CGRectMake(14, 40, 996,636 );
[self.view addSubview:[[[navController_Sections viewControllers] objectAtIndex:0] view]];
}
当我调用此方法时,应用程序崩溃了。这是崩溃日志。
崩溃日志: * 由于未捕获的异常“UIViewControllerHierarchyInconsistency”而终止应用程序,原因:“子视图控制器:< RTC_1_StoreDetailsVC: 0x71f53a0 > 应该有父视图控制器:< RTC_HomeVC: 0x758b310 > 但实际父级是:< UINavigationController: 0x71f55d0 >” *首先throw call stack: (0x1c9c012 0x10d9e7e 0x1c9bdeb 0x6838a 0x68739 0x6f5a3 0x67eed 0x4fc3 0x10ed705 0x24920 0x248b8 0xe5671 0xe5bcf 0xe4d38 0x5433f 0x54552 0x323aa 0x23cf8 0x1bf7df9 0x1bf7ad0 0x1c11bf5 0x1c11962 0x1c42bb6 0x1c41f44 0x1c41e1b 0x1bf67e3 0x1bf6668 0x2165c 0x1f82 0x1c45) libc++abi.dylib: terminate called throwing an exception
所以任何人都可以告诉我
- 这段代码有什么问题?我应该采用哪种方法来解决此崩溃?
- 如何在现有 UINavigationController 中打开另一个 UINavigationController?
谢谢。