0

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

4
  • Is "initWithCoder" logged? How did you add the text field in IB? Did you set a value? Commented Nov 2, 2016 at 14:29
  • InitWithCoder is logged. I add a customView, i change the Class in the Identity inspector and then i add the referencing outlet to a property of the same Class. I espect to see a red frame at least. But no. I don't see nothing. Commented Nov 2, 2016 at 15:47
  • Add a NSTextField and change the class. Commented Nov 2, 2016 at 22:31
  • Thank you very much!!!!! Try to do an answer post i think that's gonna be useful for anyone else! Commented Nov 3, 2016 at 9:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.