2012-11-16 41 views
0

我有一个UIView,我称之为“第二”内的另一个名为“一”的UIView。 在“秒”中,我在Inspector标识(自定义类)中分配一个类(类“Home.h”)。 班级在“第二”视图上正常工作,我没有问题。IOS:属性没有分配的类

现在我的dubt是如何通过外部类访问Home元素。如果在主页中我设置了一些变量(包括属性和合成值),我无法控制它们来自另一个类,因为它说我没有分配类Home,我该如何解决这种情况?

感谢

回答

0

我也是很新的Objective-C和Xcode的,但我相信所有你需要做的是进口的“主页”类(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; 

} 

这声明内存要在ExternalClass.m内使用的“家”类的一个对象...你将不得不到homeObject实例变量分配类'aloc'方法如下:

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

根据您在整个程序中如何使用对象,您可能必须在ExternalClass.m init方法内初始化该变量。 – Matt

相关问题