Interface Builder中的模型(MVC)?

时间:2021-06-27 11:28:19

In the Stanford iPhone course CS193P assignment 2 (free online course), the step through says to add the model into the NIB via Cocoa Touch Plugin -> Controllers -> Object. Is this for initialization purpose only? Why can't I just instantiate and initialize my model in the awakeFromNib method within the controller class itself?

在斯坦福iPhone课程CS193P作业2(免费在线课程)中,步骤说通过Cocoa Touch插件 - >控制器 - >对象将模型添加到NIB中。这仅用于初始化目的吗?为什么我不能在控制器类本身的awakeFromNib方法中实例化和初始化我的模型?

2 个解决方案

#1


You shouldn't really be creating model objects in IB. NIBs should really be exclusively for controllers and views. You then write code to create and link models and controllers

你不应该真的在IB中创建模型对象。 NIB应该专门用于控制器和视图。然后编写代码来创建和链接模型和控制器

#2


You can create the model programmatically, but I find it convenient to let IB take care of it for me.

您可以通过编程方式创建模型,但我发现让IB为我处理它很方便。

IB helps you create a singleton, link it to other things and so on.

IB可以帮助您创建单例,将其链接到其他内容等等。

#1


You shouldn't really be creating model objects in IB. NIBs should really be exclusively for controllers and views. You then write code to create and link models and controllers

你不应该真的在IB中创建模型对象。 NIB应该专门用于控制器和视图。然后编写代码来创建和链接模型和控制器

#2


You can create the model programmatically, but I find it convenient to let IB take care of it for me.

您可以通过编程方式创建模型,但我发现让IB为我处理它很方便。

IB helps you create a singleton, link it to other things and so on.

IB可以帮助您创建单例,将其链接到其他内容等等。