user2396535
user2396535

Reputation: 1

Drawing NSView and adding subviews

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?

Upvotes: 0

Views: 700

Answers (1)

Steve Waddicor
Steve Waddicor

Reputation: 2217

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.

Upvotes: 2

Related Questions