iphone - 初始化 View Controller

标签 iphone ios

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.

以上内容来自 iOS 引用:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10

文档继续描述了 Storyboard 的 View 加载顺序。

我的问题是:

1

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

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

被解释吗?

2

问题 1 与我们是否使用 Storyboard 相关吗?

最佳答案

不确定我是否正确理解了你的问题,但这是我的解释:

  1. init初始化和 View 创建是两个独立的步骤。假设我有一个 View Controller ,其表为 IBOutlet,它应该显示存储在核心数据中的食谱列表。在我的初始化方法中,我将从 CoreData 获取数据并将其存储在数组或获取结果 Controller 中。我不需要表,因此我对 self.view 属性不执行任何操作(如果还没有 View ,它会调用 viewDidLoad )。在 viewDidLoad 中,我调用 [tableView reloadData] 来重绘单元格,以便它们显示在 Controller 初始化程序中创建的 Controller 中的数据。

  2. 我认为这没有关系,但 Storyboard应该只是 View Controller 的支架,用单个文件替换单独的 Nib 。

关于iphone - 初始化 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10062269/

相关文章:

ios - UIScrollView 与 UITableView 不可滚动

iphone - 如何在 iPhone 中的 cell.backgroundview 下面添加图像?

ios - 当应用程序在前台使用 ios 8 时,调度程序 UILocalNotification 不工作

ios - 重写商店中已有的 IOS 应用程序

ios - APNS 从多个服务器发送通知

iphone - 控制 UIScrollView 越界?

ios - 显示 UIWebView 的键盘时向上移动 UIView

ios - NSPredicate用于字典数组中的内键

ios - 在 Realm 中运行线性迁移时检查属性是否存在

iphone - 在 Cocos2d iphone 中为 CCMenuItem 设置动画