Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

objective c - Access IBOutlet from other class (ObjC)

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"...

I've found answered questions like http://forums.macrumors.com/archive/index.php/t-662717.html But they're confusing.

Any help would be greatly appreciated!

Simplified Version of the Code:

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you write:

I have one NSObject with the class "A" and a second class "B" without an NSObject.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...