我创建了XIB
。InitWithCoder从来没有要求可可基于NSView的类
我创建了这个类,名为MyCustomView
,并将其分配给XIB
的文件所有者。
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) [self load];
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) [self load];
return self;
}
- (void)load {
NSArray* topLevelObjects;
[[NSBundle mainBundle] loadNibNamed:@"MyCustomView"
owner:self
topLevelObjects:&topLevelObjects];
NSView* view;
for (id aView in topLevelObjects) {
if ([umaVista isKindOfClass:[NSView class]]) {
view = umaVista;
break;
}
}
[self addSubview:view];
view.frame = self.bounds;
}
我在主应用上创建了一个NSView
。
我将该视图更改为MyCustomView
。
我运行该应用程序。 MyCustomView
的initWithCoder
不运行。 initWithFrame
不运行。 awakeFromNib
不运行。
没有任何反应。
任何想法?
你的意思是“将它分配给XIB的第一响应者”?你不能“分配”任何东西给第一响应者,这是代表动态第一响应者值的代理项目。 –
你是什么意思?这就是网络上的所有教程。 – SpaceDog
你的意思是你将它分配给“文件所有者”? –