我正在尝试使用 popToViewController,但我不断收到错误“尝试弹出到不存在的 View Controller ”?
我在设置 View 中,当用户单击“退出”时,我关闭设置 VC 并转回到调用 unwind segue 方法的主视图。在 unwind segue 方法中,我调用以下方法。
-(IBAction)endSettingsViaLogout:(UIStoryboardSegue *)segue {
//[self performSegueWithIdentifier:@"mainToLoginSegue" sender:self];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
//[self.navigationController popViewControllerAnimated:YES];
DLog(@"User finished with search");
}
当调用 poptoVC 时,我得到“试图弹出到不存在的 View Controller ”。
我对 self.navigationController.viewControllers 进行 NSLog 记录,我可以看到 VC 的堆栈,而我想要弹出的堆栈在里面?
///更新//////
好的,这就是我发现的。如果我对“设置”的转场是常规的“推送”转场,那么代码可以工作,我会被弹回到我想要的位置。如果我从屏幕左侧进行自定义转场,则它会停止工作。即使使用自定义 segue,self.navigationcontroller.viewcontrollers 也会在堆栈中显示它。那么为什么我不能弹回它呢?或者我怎样才能用自定义转场回到它?
最佳答案
我是否获得了正确的 View Controller 层次结构?
如果是这样,您实际上是在尝试“返回”到不存在的 View Controller ,因为您已经到达导航 Controller 堆栈的 Root View Controller 。在这种情况下,所有先前初始化的 Controller 都已从堆栈中弹出,您必须重新初始化并推送所需的 View Controller 。
如果我遗漏了一些重要的观点,如果您在“退出”选项可用时描述您的实际 View Controller 堆栈,那将会很有帮助。此外,如果您记录 self.navigationController.viewControllers 数组,控制台上究竟会打印什么?
关于ios - popToViewController 不工作 "Tried to pop to a view controller that doesn' t 存在”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17136892/