I have a custom view to which I need to add a couple of subviews programmatically. Which is the best place to create and add these subviews? Apple docs say:
If your view class manages one or more integral subviews, do the following: Create those subviews during your view’s initialization sequence.
This is a bit unclear to me. Should I handle that in initWithFrame, initWithCoder or somewhere else?
Note that I’m not talking about controllers here, this is a View that needs to initialize itself.
initWithFrameis the method you call to create a UIView programmatically, whileinitWithCoderis called when a UIView is instanciated from a XIB.So it all depends on how you’re going to create your containing view.
A way to cover all cases :