gpt4 book ai didi

ios - 如何查看ControllerWithRestorationIdentifierPath :coder: find an existing instance?

转载 作者:技术小花猫 更新时间:2023-10-29 10:53:31 26 4
gpt4 key购买 nike

viewControllerWithRestorationIdentifierPath:coder: 上的文档说:

Your implementation of this method should create (or find) the corresponding view controller object and return it... It is not always necessary to create a new view controller object in your implementation of this method. You can also return an existing view controller object that was created by another means. For example, if the view controller had already been loaded from a storyboard file, you would return that object rather than create a new one. [My italics.]

对我来说,这似乎完全是胡说八道。 这是一个类方法!目前我们无权访问任何实例——除非我们创建一个实例。如果有人能向我解释类方法究竟如何找到或了解“已经从 Storyboard文件加载的 View Controller ”,我将不胜感激。

编辑:要获得赏金,您必须从您自己的应用程序中向我展示类方法 viewControllerWithRestorationIdentifierPath:coder: 用于“返回一个通过其他方式创建的现有 View Controller 对象。”

最佳答案

我能想到的最常见的例子是 App Delegate 拥有的任何 View Controller 。这通常是传统应用程序中的选项卡栏 Controller 或导航 Controller ,但有时它可以是完全自定义的东西,这时此功能可能会有用。

因为 UIApplication 几乎是一个单例并且有一个委托(delegate),这意味着您的 App Delegate 具有全局状态,这使得它可以从任何地方访问,包括在类方法中:[[ UIApplication sharedApplication] delegate].

当然,任何单例都可以从任何地方访问,一种常见的模式(但我个人不喜欢)是有一个 NavigationManager 单例来管理任何全局 View Controller 转换,因此在这种情况下,您也可以访问现有实例。

关于ios - 如何查看ControllerWithRestorationIdentifierPath :coder: find an existing instance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18582098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com