UINavigationController 是否适合页面循环?

Is UINavigationController fit to pages cycles?

我是 iOS 开发的新手,我在尝试理解 UINavigationController 对象时遇到困难。我猜大多数应用程序都使用它来组织所有 windows 但我不确定。

当应用程序页面是层次结构的成员时,它似乎特别有用,但我的应用程序项目不会以这种方式组织其页面。相反,它更像是一个循环,例如有 4 页:

A​​ -> B ->C ->D -> A.

该模式是否与 UINavigationController 兼容,还是我必须使用其他替代方案?

您可以自由地将同一控制器的多个实例 class 推送到 UINavigation 控制器上,但它维护的结构是一个堆栈。您不能在该堆栈中多次重复使用同一个控制器实例,并且堆栈中的每个控制器都保留在内存中。您可能不想构建任意深的堆栈,因为它们会占用大量资源,而且许多级别的 "back" 导航会让人迷失方向。

参见 pushViewController:animated: 其中指出:

The view controller to push onto the stack. This object cannot be a tab bar controller. If the view controller is already on the navigation stack, this method throws an exception.

A UINavigationController 不是构建无限循环的 UIViewControllers 的好主意,因为 UINavigationController 的行为类似于堆栈。每个推送的 UIViewController 都会被保留并消耗内存。此外,不可能(容易)重用 UIViewControllers 来构建循环。

这可以用 UIPageViewController 存档,这样可以重复使用所有 UIViewControllers

https://developer.apple.com/library/prerelease/ios//documentation/UIKit/Reference/UIPageViewControllerClassReferenceClassRef/index.html

Cycling from last to first (and vice versa) with UIPageViewController