self.navigationcontroller 在没有导航项的情况下推送视图控制器

发布于 2024-11-04 07:18:26 字数 1038 浏览 1 评论 0原文

我对这个问题已经没有想法了。 我有一个 UITabbarcontroller 和 2 个带有导航控制器的选项卡。

我有一组用于导航的 ViewController。这些视图控制器在两个选项卡/导航控制器上以相同的顺序使用,但数据略有不同。

前一个到最后一个 Viewcontroller 正在创建一个 NSURLConnection,并且在 connectionDidFinishLoading: 中应该显示最后一个 viewcontroller,使用以下代码:

[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:lastViewController animated:YES];

这将弹出到根 viewcontroller,但永远不会推送最后一个 ViewController。 (旁注:这实际上工作了相当长的一段时间,但在从第二个选项卡栏的导航控制器使用它时停止工作)。

此外,如果我注释掉第一行:

//[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:lastViewController animated:YES];

显示最后一个视图控制器,但是错过了导航栏中的后退按钮,并且它没有被禁用或其他什么。 我怀疑 self.navigationcontroller 以某种方式返回了错误的导航控制器。就好像导航控制器“忘记”了视图控制器堆栈。

  1. 这可能与 connectionDidFinishLoading: 是不同的线程有关吗?
  2. 有人建议如何以不同的方式获取“此选项卡中的导航控制器”?

我仔细检查了代码三次,没有找到任何东西。在此之前的其他视图控制器都可以毫无问题地推送和弹出。

感谢您对此的任何帮助,我感到很困难!

I am running out of ideas with this problem.
I have a UITabbarcontroller and 2 Tabs with Navigationcontrollers in there.

I have a set of ViewControllers for the navigation. These ViewControllers are used in the same order on both tabs/navigationcontrollers with slightly different data.

The previous-to-last Viewcontroller is making a NSURLConnection, and in connectionDidFinishLoading: the last viewcontroller should be shown, using this code:

[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:lastViewController animated:YES];

This will pop to the root viewcontroller, but will never push the last ViewController.
(Sidenote: This was actually working for quite some time, but stopped working when using this also from the second tabbar's navigationcontroller).

Furthermore, if I comment out the first line:

//[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:lastViewController animated:YES];

The last viewcontroller is shown, but misses the back button in the navigation bar, and it's not disabled or something.
I suspect that somehow self.navigationcontroller is returning the wrong navigationcontroller. It's as if the navigationcontroller has "forgotten" about the viewcontroller stack.

  1. Could this be related to connectionDidFinishLoading: being a different thread?
  2. Has someone a suggestion how to get "the navigationcontroller in this tab" in a different way?

I triple checked the code up and down, I couldn't find anything. The other viewcontrollers before this one are being pushed and popped without any problems.

Thanks for any help on this, I feel stuck!

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

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

发布评论

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

评论(1

慈悲佛祖 2024-11-11 07:18:27

你说的给了我一个想法。我认为 self.navigationController 在推送后可能会被设置为 nil,因此,当您推送新的视图控制器时它不会被设置。这样做解决了问题! :)

UINavigationController *navigationController = self.navigationController;
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:lastViewController animated:YES];

What you said gave me an idea. I was thinking that self.navigationController may be set to nil after it's pushed, therefore, it's not set when you're pushing the new view controller. Doing this fixed the problem! :)

UINavigationController *navigationController = self.navigationController;
[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:lastViewController animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文