0

我在另一个名为“one”的 UIView 中有一个 UIView,我称之为“second”。在“第二”处,我在 Inspector 身份(自定义类)中分配了一个类(类“Home.h”)。该课程在“第二”视图上工作正常,我没有问题。

我现在的问题是如何通过外部类访问 Home 的元素。如果在 Home 内我设置了一些变量(使用属性和综合)我无法从另一个类控制它们,因为它说我没有分配 Home 类......我该如何解决这种情况?

谢谢

4

1 回答 1

0

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

/* 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 中使用的“Home”类的对象声明内存......然后您必须为 HomeObject 实例变量分配 Home 类的类 'aloc' 方法,如下所示:

homeObject = [[alloc Home] initWithSomeProperties:var1 andMoreProperties:varEtc];
于 2012-11-16T11:12:44.263 回答