Re: What is the difference between the -awakeFromNib and -init?
Re: What is the difference between the -awakeFromNib and -init?
- Subject: Re: What is the difference between the -awakeFromNib and -init?
- From: Luke the Hiesterman <email@hidden>
- Date: Tue, 14 Jul 2009 06:47:43 -0700
On Jul 14, 2009, at 2:20 AM, Bright wrote:
- (void)awakeFromNib{
- (id)init{
What's the difference between the two methods?
awakeFromNib is essentially a timing signifier. It gives your class a
chance to do any first actions after being loaded from a nib much in
the same way that applicationDidFinishLaunching gives your app an
entry point for first actions. init is, of course, an initializer, and
initialization code should go there. Generally speaking,
initialization code should go into init or some variation for objects
created in code. If you have an object that will be loaded from a nib
and you need to perform extra initialization, do so in initWithCoder:.
If you just want to know when your object is finished being loaded and
initialized from a nib, use awakeFromNib. The documentation provides
some rationale for awakeFromNib....
"Suppose your nib file has two custom views that must be positioned
relative to each other at runtime. Trying to position them at
initialization time might fail because the other view might not yet be
unarchived and initialized yet. However, you can position both of them
in the nib file owner’s awakeFromNib method."
Moral of the story, use awakeFromNib for setup type stuff that can't/
shouldn't go into initWithCoder: for some reason.
Luke_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden