菜鸟教程小白 发表于 2022-12-11 22:27:11

iphone - 初始化 View Controller


                                            <p><blockquote>
<p>When a view controller is first instantiated, it usually creates or
loads objects it needs through its lifetime. It should not create
views or objects associated with displaying content. It should focus
on data objects and objects needed to implement other critical
behaviors.</p>
</blockquote>

<p>以上来自iOS引用:</p>

<p> <a href="http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10" rel="noreferrer noopener nofollow">http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10</a> </p>

<p>文档继续描述了使用 Storyboard 的 View 加载序列。</p>

<p>我的问题是:</p>

<p>1</p>

<p>由于 ViewController 将与包含 View 对象的 nib 文件相关联;而且它的“viewDidLoad”方法似乎是为在加载时配置 View 对象而设计的。那么文档的建议应该如何:</p>

<p>“不应创建与显示内容相关的 View 或对象”</p>

<p>被解释?</p>

<p>2</p>

<p>问题 1 是否与我们是否使用 Storyboard 相关?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>不确定我的问题是否正确,但这是我的解释:</p>

<ol>
<li><p><code>init</code>初始化和 View 创建是两个独立的步骤。假设我有一个 ViewController ,其表为 <code>IBOutlet</code>,它应该显示存储在核心数据中的配方列表。在我的初始化方法中,我会从 CoreData 获取数据并将其存储在数组或获取的结果 Controller 中。我不需要表格,因此我对 <code>self.view</code> 属性(如果还没有 View ,则调用 <code>viewDidLoad</code> )什么都不做。在 <code>viewDidLoad</code> 中,我调用 <code></code> 来重绘单元格,以便它们显示来自 Controller 初始化程序中创建的 Controller 的数据。</p></li>
<li><p>我不认为它是相关的,但 Storyboard应该只是你的 ViewController 的脚手架,用单个文件替换单独的 nib。</p></li>
</ol></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 初始化 ViewController ,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/10062269/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/10062269/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 初始化 View Controller