如何从非初始 NavigationController 场景开始 [英] How to start from a non-initial NavigationController scene

查看:22
本文介绍了如何从非初始 NavigationController 场景开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模仿 Apple 默认应用照片"中的导航逻辑.下面是应用导航逻辑的说明.

当您第一次启动应用时,您会进入位于应用中第三高层次结构级别的时刻"视图.这很有趣,因为整个照片"选项卡似乎嵌入到单个 NavigationController 中.

但是,如果所有场景都嵌入到单个 NavigationController 中,您如何从非初始场景开始?

这是我的hackish实现,没有将场景嵌入到任何NavigationController中(所有segue都显示为show:

它导致了我想要的行为,但我不确定内存问题.我是否在每个循环中分配新的 VC?故事板看起来不正确.

作为答案,一个简单的 Storyboard 捕获和简短的解释会很好.

解决方案

正如我在评论中所说,您需要修改 UINavigationController.viewControllers 属性,您可以使用 setViewControllers(_:animated:) 方法或直接修改 .viewControllers 属性来做到这一点,其中 rootViewController 将是 viewControllersArray[0]topViewController 将是 viewControllersArray[count-1]

这个属性的描述和细节可以在UINavigationController文档中找到

viewControllers

<块引用>

财产

当前在导航堆栈上的视图控制器.

声明SWIFT

var viewControllers: [UIViewController]

<块引用>

讨论 根视图控制器位于数组中的索引 0,后视图控制器位于索引 n-2,顶部控制器位于索引 n-1,其中 n 是数组中的项数.

为这个属性分配一个新的视图控制器数组是相当于调用 setViewControllers:animated: 方法动画参数设置为 false.

示例

 let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)让 firstViewController = storyboard.instantiateViewController(withIdentifier: "FirstViewController") 作为?第一视图控制器让 secondViewController = storyboard.instantiateViewController(withIdentifier: "SecondViewController") 作为?第二个视图控制器让 thirdViewController = storyboard.instantiateViewController(withIdentifier: "ThirdViewController") 作为?第三个视图控制器self.navigationController?.setViewControllers([firstViewController,secondViewController,thirdViewController], 动画: false)

I'm trying to mimic the navigation logic in Apple default app "Photos". Below is the illustration of the app navigation logic.

When you first start the app, you land on "Moments" view which is at the third highest hierarchy level in the app. It's quite interesting because the whole "Photos" tab seems like to be embedded into a single NavigationController.

However, if all scenes are embedded into a single NavigationController how do you start from a non-initial scene?

Here's my hackish implementation without embedding scenes into any NavigationController(all the segues are presented as show:

It results the behavior I wanted but I'm not sure about the memory issue. Am I allocating new VCs every loop? And the storyboard just doesn't look right.

As an answer, a simple Storyboard capture with brief explanation would be nice.

解决方案

As I said in my comments you need to modify the .viewControllers property of your UINavigationController you can do this using setViewControllers(_:animated:) method or modifying directly .viewControllers property where rootViewController will be the viewControllersArray[0] and topViewController will be viewControllersArray[count-1]

This property description and details can be founded in the UINavigationController documentation

viewControllers

Property

The view controllers currently on the navigation stack.

Declaration 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.

example

    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)

这篇关于如何从非初始 NavigationController 场景开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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