gpt4 book ai didi

ios - '试图弹出一个不存在的 View Controller

转载 作者:行者123 更新时间:2023-11-29 12:55:49 25 4
gpt4 key购买 nike

我知道很多用户都问过这个问题,但我没有找到适合我的问题的解决方案。

我正在使用 splitViewController,我隐藏了我的 rootViewController 并且在 detailViewController 中我正在推送和弹出不同的 ViewControllers

当我从 ViewController-1 导航到 ViewController-2 时一切正常,当我返回到 ViewController-1viewController-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 和 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];
}

最佳答案

最后我找到了解决方案,这是一个非常愚蠢的错误,我的 ViewController-3 是 UINavigationController 的委托(delegate)。

当我尝试将 viewController-2 弹出到 viewController-1 时,我的 UINavigationController 正在寻找它的委托(delegate)方法 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)已弹出的 viewController-3 中的动画

我将 rootViewController 设为 UINavigationController 的委托(delegate),现在它工作正常。

关于ios - '试图弹出一个不存在的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21154437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com