我正在尝试模仿 Apple 默认应用程序“照片”中的导航逻辑。下面是应用导航逻辑的说明。
当您第一次启动该应用程序时,您会进入“ friend 圈” View ,该 View 位于该应用程序的第三高层级。这非常有趣,因为整个“照片”选项卡似乎都嵌入到单个 NavigationController 中。
但是,如果所有场景都嵌入到单个 NavigationController 中,您如何从非初始场景开始?
这是我的 hackish 实现,没有将场景嵌入到任何 NavigationController 中(所有 segues 都显示为 show
:
它会导致我想要的行为,但我不确定内存问题。我是否在每个循环中分配新的 VC?而且 Storyboard看起来不对。
作为答案,一个简单的 Storyboard 捕获和简短的解释会很好。
最佳答案
正如我在评论中所说,您需要修改 UINavigationController
的 .viewControllers
属性,您可以使用 setViewControllers(_:animated:)
方法或直接修改 .viewControllers
属性,其中 rootViewController
将是 viewControllersArray[0]
而 topViewController
将是 viewControllersArray[count-1]
此属性描述和详细信息可以在 UINavigationController
文档中找到
viewControllers
Property
The view controllers currently on the navigation stack.
声明 SWIFT
var viewControllers: [UIViewController]
Discussion The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.
Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to false.
示例
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let firstViewController = storyboard.instantiateViewController(withIdentifier: "FirstViewController") as? FirstViewController
let secondViewController = storyboard.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController
let thirdViewController = storyboard.instantiateViewController(withIdentifier: "ThirdViewController") as? ThirdViewController
self.navigationController?.setViewControllers([firstViewController,secondViewController,thirdViewController], animated: false)
关于ios - 如何从非初始 NavigationController 场景开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46002976/