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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to