我知道很多用户都提出了这个问题,但我没有找到适合我的问题的解决方案。
我正在使用splitViewController
,我隐藏了我的rootViewController
,而detailViewController
我正在推动并弹出不同的ViewControllers
。
当我从ViewController-1
导航到ViewController-2
时,当我再次使用ViewController-1
从viewController-2
返回[self.navigationController popViewControllerAnimated:NO ];
时工作正常。
现在,当我从ViewController-2
导航到ViewController-3
并返回ViewController-2
时,工作正常。
但是现在当我从ViewController-2
返回ViewController-1
时,它会因为跟随错误而崩溃。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist
我启用了僵尸对象。 image
我的应用程序的代码如下: 的 1.AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.splitViewController =[[UISplitViewController alloc]init];
// create master and detailViewController for splitView
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil] ;
//create navigation controller for root and detailViewController
self.rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
self.detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
//make hide navigation bar
self.rootNav.navigationBarHidden = YES;
self.detailNav.navigationBarHidden = YES;
//set splitViewController with root and detail viewController
self.splitViewController.viewControllers=[NSArray arrayWithObjects:self.rootNav,self.detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
// Now Add the split view controller's view to the window and display.
[self.window addSubview:self.splitViewController.view];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
2.push and pop ViewControllers
push()
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
MyViewController *Vc = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[appDelegate.detailNav pushViewController:Vc animated:NO];
}
pop()
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.detailNav popViewControllerAnimated:NO];
}
答案 0 :(得分:0)
最后我找到了解决方案,这是非常愚蠢的错误,我的ViewController-3是UINavigationController的委托。
当我试图将viewController-2弹出到viewController-1时,我的UINavigationController在viewController-3中寻找它的委托方法- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
。
我将rootViewController设置为UINavigationController的委托,现在它正常工作。