【发布时间】:2013-05-23 11:10:34
【问题描述】:
好的,所以我有一个名为“AmazingClass”的类,我用它来生成一个工作表来保存文件。其中有一个带有额外选项的 NSView。它工作得很好,但现在我想要更多具有相同功能的窗口,但使用不同的选项,因为它们应该保存不同的文件格式。
基本布局是这样的:
AmazingClass.h
#import <Cocoa/Cocoa.h>
@interface AmazingClass : NSObject {
NSView * _accessoryView;
BOOL _prepared;
}
@property (assign, nonatomic) IBOutlet NSView * accessoryView;
@property (copy, nonatomic) NSString * nibForAcessoryView;
// Methods that generate the save window
- (void) prepareToRun;
@end
AmazingClass.m
#import "AmazingClass.h"
@implementation AmazingClass
@synthesize accessoryView = _accessoryView;
@synthesize nibForAcessoryView;
// Other stuff here
- (void) prepareToRun {
// stuff here
if ([self nibForAcessoryView] == nil) {
[self setNibForAcessoryView: @"AmazingWindow"];
}
[NSBundle loadNibNamed:[self nibForAcessoryView] owner:self];
_prepared = YES;
}
现在我想用同一个类来处理不同的 NSView,像这样:
NotSoAmazing.h
#import "AmazingClass.h"
@interface NotSoAmazing : AmazingClass {
IBOutlet NSView * subAccessoryView;
}
@end
NotSoAmazing.m
#import "NotSoAmazing.h"
@implementation NotSoAmazing
- (void) prepareToRun {
[self setAccessoryView:subAccessoryView];
[self setNibForAcessoryView: @"NotSoAmazingWindow"];
[super prepareToRun];
}
然后我创建一个新的 NSView,文件的所有者设置为类“NotSoAmazing”,我在界面中创建所有链接并执行代码。
如果有一个接口链接到原始类,我会使用原始接口而不是替代接口。如果我删除所有链接,则不会显示任何内容。
因此,我的问题是:如何处理儿童班的 IBoutlets 以采取不同的观点?
【问题讨论】:
-
"如果有一个接口链接到原来的类,我使用原来的接口而不是替代接口。如果我删除所有链接,什么都不会显示。"这是什么意思?您在这里使用接口和链接这两个词是什么意思?
标签: objective-c macos cocoa