ios - 如何从非初始 NavigationController 场景开始

标签 ios swift uinavigationcontroller segue xcode-storyboard

我正在尝试模仿 Apple 默认应用程序“照片”中的导航逻辑。下面是应用导航逻辑的说明。

enter image description here

当您第一次启动该应用程序时,您会进入“ friend 圈” View ,该 View 位于该应用程序的第三高层级。这非常有趣,因为整个“照片”选项卡似乎都嵌入到单个 NavigationController 中。

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

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

它会导致我想要的行为,但我不确定内存问题。我是否在每个循环中分配新的 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/

相关文章:

ios - 需要从呈现的 UINavigationController 中返回到呈现的 UIViewController

swift - interactivePopGestureRecognizer 损坏 Root View Controller 上的导航堆栈

ios - UIImagePNGRepresentation 在 CIFilter 之后返回 nil

ios - 什么时候调用协议(protocol)函数?

ios - 处理 map 上的水龙头

swift - "' C ' is not identical to ' UInt8 '"在 Swift 中使用 += 运算符时

ios - 从 NSURLConnect.SendAsyncronousRequest 返回值

ios - UINavigationController 上的 UIBarButton 因此适用于所有 subview

python - 用Python 3编写iOS游戏的最佳库是什么?

ios - ./configure 参数为 iOS 构建 C 库