When view is loaded manually, developer remains in control when it comes to initializations, we choose what initializer to call, what variables to set etc.
When view
When a view is loaded from a nib or storyboard, it's -initWithCoder:
method is called. Like -initWithFrame:
, -initWithCoder:
is a designated initializer for UIView. If you're going to do any custom initialization for a UIView subclass, you should make sure that it happens for both these methods. One common technique is to add a common initialization method that you call from both -initWithFrame:
and -initWithCoder:
. See my answer to Custom view and implementing init method? for a more detailed description.
Note that the documentation for -initWithFrame:
explains:
If you use Interface Builder to design your interface, this method is not called when your view objects are subsequently loaded from the nib file. Objects in a nib file are reconstituted and then initialized using their initWithCoder: method, which modifies the attributes of the view to match the attributes stored in the nib file.