Reputation: 29
I created a Subclass of NSTextField. If i use it via code there's no problems, everything is fine and the component works as intended. If i use it via Interface Builder the component just won't show.
Here is my inits for the subclass:
-(instancetype)initWithFrame:(NSRect)frameRect{
self = [super initWithFrame:frameRect];
if(self){
[self setAlignment:NSTextAlignmentCenter];
[self setBackgroundColor:[NSColor blueColor]];
[self setBezeled:NO];
[self setEditable:NO];
[self setSelectable:NO];
[self.cell setUsesSingleLineMode:YES];
}
return self;
}
-(instancetype)initWithCoder:(NSCoder *)coder{
self = [super initWithCoder:coder];
if(self){
NSLog(@"initWithCoder");
[self setAlignment:NSTextAlignmentCenter];
[self setBackgroundColor:[NSColor redColor]];
[self setBezeled:NO];
[self setEditable:NO];
[self setSelectable:NO];
[self.cell setUsesSingleLineMode:YES];
}
return self;
}
For instance, if i create two components , one by code and one by Interface builder i can see only the first component, with blueBackground.
Any ideas? Thanks
Upvotes: 0
Views: 80
Reputation: 15589
When adding a subclass of an Appkit class in IB, add the nearest superclass and change the class in the Identity Inspector. So if you created a subclass of NSTextField
, add a NSTextField
and change the class.
Upvotes: 1