View Full Version : init method not called
Nov 2, 2009, 01:56 PM
The init method is NOT called on the second snippet of code, but is called on the first snippet. I don't understand.
Nov 2, 2009, 02:03 PM
Your method isn't called init
Nov 2, 2009, 03:25 PM
initWithCoder is used to unarchive content from a file.
You'll want to read "Archives and Serializations Programming Guide for Cocoa (http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Archiving/Archiving.html)" for more on that.
Nov 2, 2009, 10:11 PM
My Bad! I copied over other code I was trying out. The correct posting of the code that's NOT working is:
Sorry for the confusion. Thanks for your help.
Nov 2, 2009, 10:22 PM
How are you instantiating this class? Can you post the code where you are using the class?
Is this RootViewController from inside a XIB/NIB? If so, it technically doesn't get init'ed when the app is started, but rather gets unarchived from the XIB. When this happens, the awakeFromNib method is called.
Basically the rule of thumb, is if the class is being instantiated from code, init is called, but if the class is being instantiated from Interface Builder, then you want awakeFromNib.
Nov 4, 2009, 04:18 PM
One from xib, one from code. Thank you for helping clarify this basic element, and the clear manner you made it clear for me. I have been studying Cocoa since March, and this basic element had escaped me.