Initializing View Instances Created in Interface Builder
View instances that is created in Interface Builder don ' t call when initWithFrame: their nib files is loaded, which often causes Confusion. Remember that Interface Builder archives an object when it saves a nib file, so the view instance would already have been C Reated and would initWithFrame: already have been called.
The awakeFromNib method provides an opportunity to provide initialization of a view when it's created as a result of a nib file Being loaded. When a nib file that contains a view object is loaded, each view instance receives a message when all the awakeFromNib objects H Ave been unarchived. This provides the object a opportunity to initialize any attributes that is not archived with the object in Interface Bu Ilder. DraggableItemViewThe class is extremely simple, and doesn ' t implement awakeFromNib .
There is exceptions to the initWithFrame: behavior when creating view instances in Interface Builder. Its important-understand these exceptions to ensure, your views initialize properly.
If you had not created a Interface Builder palette for your custom view, there is both techniques you can use to Crea Te instances of your subclass within Interface Builder. The first is a using the Custom View proxy item in the Interface Builder containers palette. This view was a stand-in for your custom view, allowing your to position and size of the view relative to other views. You then specify the subclass of NSView that The view represents using the inspector. When the nib file was loaded by the application, the custom view proxy creates a new instance of the specified view Subclas S and initializes it using THE  initwithframe: method, passing along any autoresizing flags as Neces Sary. The view instance then receives an awakefromnib message.
The second technique applies when your custom subclass inherits from a view this Interface Builder provides direct support For. To take advantage of Interface Builder's built-in support, create a instance of the view that Interface Builder have Direc T support for, and then use the inspector to change the class name to your custom subclass. For example, can create a NSScrollView instance in Interface Builder and specify that a custom subclass ( MyScrollView ) should is US Ed instead, again using the inspector. In the If the nib file is loaded by the application, the view instance have already been created and the MyScrollView imp Lementation of is initWithFrame: never called. The MyScrollView instance receives an awakeFromNib message and can configure itself accordingly.
"Cocoa" Initializing View Instances Created in Interface Builder