首先启动导航堆栈的第二个视图控制器 [英] Start second view controller of navigation stack first

查看:21
本文介绍了首先启动导航堆栈的第二个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个默认的日历应用.

There is a default calendar app.

它从下一个视图控制器开始,后退按钮已经存在,就像在这个控制器之前启动了其他一些视图控制器一样:

It starts with the next view controller and back button is already there like there some other view controller was started before this one:

当你按下后退按钮时,你会得到下一个视图控制器:

When you press back button you get the next view controller:

他们是怎么做到的?

在我的应用程序中,我需要相同的逻辑(以最新或默认类别启动视图控制器,但用户可以按后退按钮选择不同的类别)

In my app I need the same logic (to start a view controller with the latest or default category but users can press back button to select a different category)

推荐答案

如果我要这样做,我会首先使用 pushViewController(animated:) 将月视图推送到导航上堆栈,在根视图控制器的 viewWillAppear(animated:) 方法中使用 animated: false.日历将在导航堆栈中的一层深出现在用户面前.

If I were to do this, I would start by simply using pushViewController(animated:) to push the month view onto the navigation stack, with animated: false in the root view controller's viewWillAppear(animated:) method. The calendar would appear to the user already one level deep in the navigation stack.

因此,第一个控制器是年视图,然后月视图是压入堆栈的第二个控制器,但这一切都发生在用户看到任何视图之前.很简单吧?

So, the first controller is the year view, and then the month view is the second one pushed onto the stack, but it all happens before the user has seen any of the views. Simple, right?

这里是 UINavigationController 的文档,以防万一.

这篇关于首先启动导航堆栈的第二个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆