开发者

Creating instance of a viewController

My question is quite basic, I 开发者_如何学Pythonguess. When we create an instance of a viewController in another viewController, it is whose instance that we create? Is it of viewController.h or viewController.m?

What I have learned is, interface cannot be instantiated. Thus, .h cannot be instantiated. So, is it .m that we instantiate?


We create instances of a class, not an interface or implementation.

In Objective-C a class should contain both interface(.h) and implementation(.m) files. Both the interface and the implementation comprises a class in a typical MVC architecture. Interface is an interface(literally) to a class using which we get access to the class.

If you keep the interface in .h file, you can import the .h file from other classes and use its properties and methods by instantiating the class. If you write the interface in .m file then that class will be accessible from that particular .m file alone. Note that we can import .h files not .m files.


Interface just define what class has to do.So, we are importing .h file to know what class is doing.

When you are allocating view controller, you are neither creating the instance of .h nor .m file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜