如何返回 UINavigationController 中的一个视图?

发布于 2024-09-10 08:40:47 字数 64 浏览 2 评论 0原文

是否有一种方法可以返回 UINavigationController 上堆栈中的一个视图?或者具有特定标题的视图?

Is there a method to go back one view in the stack on a UINavigationController? Or to a view with a specific title?

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

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

发布评论

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

评论(3

太阳哥哥 2024-09-17 08:40:48

我并不是有意无礼,但这确实有详细记录。在 UINavigationController 上进行 google 搜索甚至 Apple 文档搜索都会找到您所需要的内容。要以编程方式弹出当前视图控制器,您可以使用:

[[self navigationController] popViewControllerAnimated:YES];

要弹出到特定视图控制器,您可以使用:

[[self navigationController] popToViewController:controller animated:YES];

您必须首先遍历视图控制器列表,然后根据您要查找的内容检查标题,然后将其传递给此方法。

I don't mean to be rude, but this is really well documented. A google search or even an Apple documentation search on UINavigationController will turn up exactly what you need. To programmatically pop the current view controller you use:

[[self navigationController] popViewControllerAnimated:YES];

To pop to a specific view controller, you use:

[[self navigationController] popToViewController:controller animated:YES];

You will have to iterate through the list of view controllers first and check the title against what you're looking for and pass that to this method.

迟月 2024-09-17 08:40:48

看看popViewControllerAnimated:

从文档中:此方法从堆栈中删除顶部视图控制器,并使堆栈的新顶部成为活动视图控制器。

用法如下:

[aViewController popViewControllerAnimated:YES];

Take a look at popViewControllerAnimated:.

From the documentation: This method removes the top view controller from the stack and makes the new top of the stack the active view controller.

Usage is something like:

[aViewController popViewControllerAnimated:YES];
手心的海 2024-09-17 08:40:48

Swift 3 版本

navigationController?.popViewController(animated: true)

要弹出到特定视图控制器,您可以使用:

navigationController?.popToViewController(controller, animated: true)

您必须首先遍历视图控制器列表,然后根据您要查找的内容检查标题,然后将其传递给此方法。

Swift 3 version

navigationController?.popViewController(animated: true)

To pop to a specific view controller, you use:

navigationController?.popToViewController(controller, animated: true)

You will have to iterate through the list of view controllers first and check the title against what you're looking for and pass that to this method.

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