I'm trying to make a custom NSView subclass. It does some drawing inside drawRect method. It also needs to have subviews(a couple of NSTextField s). So my question is should I add these NSTextFields inside of drawRect method or elsewhere?
1 Answers
2
votes
Definitely elsewhere. -drawRect should only do drawing, nothing else.
If you are creating the view programatically, you can override the -initWithFrame method, call [super initWithFrame:frame] and then add your subviews there.
If the view is in an xib file, then you can create the subviews in -awakeFromNib. Or simply add them in the nib itself in Interface Builder.