Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I call [super awakeFromNib]?

If i implement my own version of awakeFromNib, should I call [super awakeFromNib] at the end of my method?

like image 908
cfischer Avatar asked Oct 21 '10 16:10

cfischer


People also ask

When awakeFromNib is called?

awakeFromNib gets called after the view and its subviews were allocated and initialized. It is guaranteed that the view will have all its outlet instance variables set.

When to use awakeFromNib?

Typically, you implement awakeFromNib for objects that require additional set up that cannot be done at design time. For example, you might use this method to customize the default configuration of any controls to match user preferences or the values in other controls.


1 Answers

awakeFromNib for UIKit (iOS):

You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.

awakeFromNib for AppKit (Mac):

(not true anymore, if using OS X 10.6 or higher)

You should call the super implementation of awakeFromNib only if you know for certain that your superclass provides an implementation. Because the Application Kit does not provide a default implementation of the awakeFromNib method, calling super results in an exception if the parent class does not implement it. Classes whose immediate parent class is NSObject or NSView do not need to call the super implementation. For any other classes, you can use the instancesRespondToSelector: class method of NSObject to determine if the parent class responds to awakeFromNib and call the method if it does.

like image 72
ma11hew28 Avatar answered Sep 19 '22 02:09

ma11hew28