我想我的问题很基本。当我们在另一个viewController中创建一个viewController的实例时,我们创建的是谁的实例?是viewController.h
还是viewController.m
?
我学到的是,接口(interface)不能被实例化。因此,.h 不能被实例化。那么,我们实例化的是.m吗?
最佳答案
We create instances of a class, not an interface or implementation.
在 Objective-C 中,一个类应该同时包含接口(interface) (.h) 和实现 (.m) 文件。在典型的 MVC 架构中,接口(interface)和实现都包含一个类。接口(interface)是一个类的接口(interface)(字面意思),我们使用它来访问该类。
如果您将接口(interface)保留在.h文件中,您可以从其他类中导入.h文件并使用它的属性和方法通过实例化类。如果您在 .m 文件中编写接口(interface),那么可以单独从特定的 .m 文件访问该类。请注意,我们可以导入 .h 文件而不是 .m 文件。
关于iphone - 创建 viewController 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7185830/