UIStoryboard popViewController

发布于 2024-12-27 11:32:42 字数 530 浏览 3 评论 0原文

我在应用程序中使用 UISegue 在应用程序中的视图控制器之间自动转换。我将它们称为 A 和 B。

它按预期工作,但是当我想从 B 弹回到 A 时,我尝试调用 [self.navigationController popViewController] 但是 B 的 navigationController 属性报告 null。


作为第二次尝试,我尝试将按钮映射到 UISegue 返回视图控制器 A。
然而这只是创建了一个新的 ViewController。

作为解决方法,我最终做的解决方法是从 UIStoryboard 检索 B viewcontroller 并调用 [A.navigationController PushViewController:B]

此时,调用 [B.navigationController popViewController] 按预期工作。

这似乎是错误的,从故事板继续我怎样才能返回到以前的视图控制器?

I'm using a UISegue in my application to automatically transition between viewcontrollers in my application. I'll call them A and B.

It worked as expected, however when I wanted to pop-back to the A from B, I attempted to call
[self.navigationController popViewController] however the B's navigationController property reports null.


As a second attempt I attempted to map a button, to a UISegue back to view controller A.
However this just creates a new ViewController.

As a work around, I ended up doing as a work around was to retrieve the B viewcontroller from the UIStoryboard and calling [A.navigationController pushViewController:B]

At which point, calling [B.navigationController popViewController] worked as expected.

This seems wrong, from a storyboard segue how can I return to the previous view controller?

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

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

发布评论

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

评论(1

世界和平 2025-01-03 11:32:42

我不知道你的 A 和 B 控制器的类(无论是 UIViewController、UITableViewController 还是 UINavigationController),但如果你遵循以下模式,它应该可以工作。

  • 在空故事板中,插入 UINavigationController。这将在故事板中引入两个窗口,并用箭头(segue)链接。右边的应该是控制器 A。

  • 在 A 中,假设您添加了一个按钮。该按钮会将 B 推入导航堆栈。

  • 然后,添加第二个控制器 B,并从控制器 A 中的按钮拖动到控制器 B,并从弹出的菜单中选择“推送”。

如果您只使用 UIViewController (A) 并推送 B,则没有 navigationController 来处理弹出操作。

希望有帮助。

I don't know about the class of your A and B controllers (whether UIViewController, UITableViewController or UINavigationController), but if you follow the following pattern, it should work.

  • In an empty storyboard, insert a UINavigationController. This will bring in two windows to the storyboard, linked with an arrow (a segue). The one on the right should be controller A.

  • In A, let's say, you add a button. The button will push B into the navigation stack.

  • Then, you add the second controller B, and drag from the button in controller A to controller B, and choose "push" from the popped menu.

If you only use a UIViewController (A) and push B, there is no navigationController to take care of popping.

Hope that help.

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