- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
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/
NSCoding 需要 init(coder:),但也有此方法的可选版本 init?(coder:)。 如果返回 nil,具体应该怎么办?这甚至是一个问题吗? 假设您正在使用 init(coder:)
我正在处理一个 MATLAB Coder 项目,我想在其中加载一些常量值。在尝试了多种可能性之后,均未成功,我提出了“coder.load”指令,该指令从 MAT 文件加载变量并假定它们作为生成的 C
我正在构建 Apache Beam 管道,但在尝试导入管道选项时遇到了 AttributeError。 我正在使用 python3.6 在干净的虚拟环境中的 Ubuntu 服务器上进行测试 步骤: v
我需要使用 y=coder.ceval() 从 matlab 调用 c 函数,并从该函数返回一个字符串。但是 coder.ceval() 函数只允许我返回标量值。然而 String 是一个 char
最近我从 Xcode 6.2 更新到 Xcode 6.3 beta 4 并打开了我的项目。我在 init() 上遇到以下错误:Missing argument for parameter 'coder
我正在 simulink 中开发一个系统控制,我想在嵌入式板上运行这个模型。因此,我想将模型的输入和输出与特定函数(在模型外部手写)联系起来。 为了理解:我有一个输入,它是一个包含 8 个元素的数组。
我正在使用 Matlab 处理大型数组中的大量数据。我的程序运行良好,现在我已将其转换为 C,但遇到了最大数组大小问题。 定义emxArray时,定义如下: struct emxArray_real_
我正在尝试在一段代码中使用动态增长的结构数组,该代码应该使用 Coder 转换为 C: 我初始化该结构,然后为编码器声明其字段可变大小,然后我继续扩展该结构。请注意,我已经简化了这个示例以帮助生成代码
我已将自定义 UIButton 编码为: class AccountOpeningButton: UIButton { required init?(coder aDecoder: NSCode
我正在通过在线类(class)学习 iOS 开发,每次我制作自定义 View (自定义表格 View 单元格、 Collection View 单元格等)时,讲师总是实现此初始化程序: require
为将来阅读本文的人提供一些背景知识(以防它未锁定)。我倾向于使用高级语言进行编程以首先理解问题。在涵盖所有可能的极端情况后,我继续将代码翻译成 C++(或 C)。 我编写的大部分代码都包含数学,因此
我正在尝试为1.7.10安装地雷编解码器包。我已经下载了src forge软件包,并且正在使用终端。我用它来安装它。 http://www.minecraftforge.net/wiki/Instal
我正在尝试使用 Matlab 编码器从 .m 文件生成 mex 代码文件。其代码是 function [result,x]=tesrank(A,x) result = []; n = x; for c
我正在尝试使用 Matlab Coder 工具将一些 matlab 代码转换为 c 动态库 (.dll)。我正在一些简单的示例代码上尝试它,但我不断收到相同的错误,但找不到解决方案。 我的代码是: f
我正在学习 Java,作为高中作业之外的个人项目,我决定制作一些数学求解程序来练习。 为了热身,我决定编写一个基本的计算器程序......并且它有效......有点。所以...请帮助我! 目标: ->
当我尝试运行 int(coder:) 时它显示此错误,我不知道为什么? “不可失败的初始化器要求 init(coder:) 不能被可失败的初始化器 ('init?') 满足” class Note:
需要初始化一个对象,但我的初始化程序不合作。到目前为止我已经知道了,但我不确定如何将参数传递给我的对象初始值设定项。 init(coder aDecoder: NSCoder, caseImage:
我有一个继承自 PFTableViewCell 的自定义类。我想使用 Storyboard 来初始化类(class)。我使用“tableView.dequeueReusableCellWithIden
我正在尝试暂停或停止一个永远重复的 SKAction,这应该在用户按下暂停按钮时发生。我找到了一种停止音乐的方法,但由于这个错误,我无法调用它所在的函数。它准确地说:Missing argument
我有一个函数 sq_dist()。可以像这样调用此函数 sq_dist(a,b) 或 sq_dist(a)。此功能包括缓慢的操作,因此我正在尝试制作它的 Mex 版本,希望它运行得更快。我正在使用 M
我是一名优秀的程序员,十分优秀!