IOS:未分配的类的属性

时间:2012-11-16 10:54:28

标签: ios class uiview

我有一个UIView,我在另一个名为“one”的UIView中称为“第二个”。 在“秒”,我在Inspector标识(Custom类)中分配一个类(类“Home.h”)。 该课程在“第二”视图中正常工作,我没有问题。

我的目前是如何通过外部类访问Home的元素。如果在Home里面我设置了一些变量(有属性和合成),我无法从另一个类控制它们,因为它告诉我类Home它没有分配......我怎么能解决这个问题?

感谢

1 个答案:

答案 0 :(得分:0)

我也是Objective-C和Xcode的新手,但我相信你所要做的就是将“Home”类(Home.h)的头文件导入到你要在其中使用它的外部类中。在这个外部类中,你必须实例化一个home类的对象。可能看起来像这样的东西:

/* File: "ExternalClass.h"
* This is the Super-View class of the "Home" class
*/

/* An example using Cocoa rather than Cocoa Touch */
#import <Cocoa/Cocoa.h>

// Imports a quick reference to the class without loading the classes methods
@class Home;

@interface ExternalClass : NSView {

/* This creates an object of class "Home" in which a pointer for the "Home" class can be stored
 * From here all you would have to do is import the 'Home.h' file to the 'ExternalClass.m' file
 * and instantiate home objects and call methods of the 'home' class within the 'ExternalClass.m' files methods
 */
Home *homeObject;

}

这为在HomeClass.m中使用的“Home”类的对象声明了内存...然后,您必须为Home类分配homeObject实例变量类'aloc',如下所示:

homeObject = [[alloc Home] initWithSomeProperties:var1 andMoreProperties:varEtc];