从其他类(ObjC)访问IBOutlet [英] Access IBOutlet from other class (ObjC)
问题描述
我已经找到了一些答案,但我没有得到任何他们的工作。我有一个NSObject有类A和第二个类B没有NSObject。在类A是我的IBOutlets定义,我似乎无法找出如何访问这些插座从类B...
I've googled around and found some answers but I didn't get any of them to work. I have one NSObject with the class "A" and a second class "B" without an NSObject. In class "A" are my IBOutlets defined and I can't seem to figure out how to access those outlets from class "B"...
回答问题,例如 http://forums.macrumors.com/archive/index .php / t-662717.html 但他们很混乱。
I've found answered questions like http://forums.macrumors.com/archive/index.php/t-662717.html But they're confusing.
任何帮助将非常感谢!
代码的简化版本:
aClass.h:
#import <Cocoa/Cocoa.h>
@interface aClass : NSObject {
IBOutlet NSTextField *textField;
}
@end
aClass.m:
#import "aClass.h"
@implementation aClass
// Code doesn't matter
@end
bClass.h:
#import <Cocoa/Cocoa.h>
@interface bClass : NSObject {
}
@end
bClass.m:
#import "aClass.h"
#import "bClass.h"
@implementation bClass
[textField setStringValue: @"foo"];
@end
推荐答案
/ p>
When you write:
我有一个NSObject类的
A和第二个类B没有
NSObject。
I have one NSObject with the class "A" and a second class "B" without an NSObject.
它告诉我你没有你的基本概念。
阅读苹果的目标C介绍和教程项目。
It tells me that you don't have your head around the basic concepts. Read through Apple's objective-C introduction, and the tutorial projects.
这篇关于从其他类(ObjC)访问IBOutlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!