尝试从导航堆栈中弹出视图时断言失败

发布于 2024-12-26 02:34:52 字数 486 浏览 1 评论 0原文

我正在尝试弹出到导航堆栈中的特定视图控制器,但我做错了一些事情,因为当我尝试执行代码时弹出此错误

Assertion failure in -[UINavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-1912.3/UINavigationController.m:2229

这是导致问题的代码

FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController.xib" bundle:nil];

    [self.navigationController popToViewController:firstViewController animated:YES];

I'm trying to pop to a specific view controller that is in the navigation stack but I am doing something wrong as I am getting this error pop up when I try to execute the code

Assertion failure in -[UINavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-1912.3/UINavigationController.m:2229

Here is the code thats causing the issue

FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController.xib" bundle:nil];

    [self.navigationController popToViewController:firstViewController animated:YES];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见你 2025-01-02 02:34:52

设法找到一个完美运行的其他示例。

//只需选择 objectAtIndex 编号即可弹出到导航堆栈上的特定点

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

希望这会有所帮助。

Managed to find an example else where which works perfectly.

//Just choose objectAtIndex number to pop to a particulart point on the navigation stack

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

Hope this helps.

可是我不能没有你 2025-01-02 02:34:52

您无法弹出尚未推送的控制器实例,即使它可能与您想要返回的另一个控制器相同。

在您的代码片段中,您尝试将导航控制器的堆栈弹出到新创建的对象。该控制器不在堆栈上,因为您刚刚创建了它。由于导航控制器找不到您正在寻找的控制器,因此会抛出错误。

You cannot pop an instance of a controller that you have not pushed yet, even though it may be identical to another controller to which you would like to return.

In your code snippet, you are trying to pop the stack of the navigation controller to a newly created object. This controller is not on the stack, because you have just created it. Since the navigation controller cannot find a controller that you are looking for, it throws an error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文