Re: Is awakeFromNib REALLY first to run?
Re: Is awakeFromNib REALLY first to run?
- Subject: Re: Is awakeFromNib REALLY first to run?
- From: "Dennis C. De Mars" <email@hidden>
- Date: Sat, 30 Jun 2001 11:27:37 -0700
on 6/29/01 7:29 PM, email@hidden at email@hidden
wrote:
>
Hi all,
>
>
I've been playing around with Cocoa, trying to get through the Oreilly
>
book, and I've come across something that doesn't seem right. Although
>
the Oreilly book says that awakeFromNib is always run first. However, in
Can you give me the page number where they say that? Because it seems to be
exactly the opposite of how awakeFromNib actually works.
I always think of awakeFromNib as a more general version of the
"FinishCreateSelf" method in PowerPlant views. It is meant to be run after
all of the objects in the nib are created, initialized and connected to each
other. Maybe a more explanatory name would have been
"FinishedElaboratingNib" or something of that sort, which would convey more
directly the fact of the matter: awakeFromNib is, basically, always called
_last_, not first.
The first mention of awakeFromNib in the O'Reilly book "Learning Cocoa" is
on page 77 where they say:
"After a nib file has been completely unpacked and its objects connected,
the runtime system sends the awakeFromNib message to all objects that were
derived from information in the nib file, signaling that the loading process
is complete. All object's outlets are guaranteed to be initialized when
awakeFromNib is called."
See, it's called _last_, after all this other stuff happens. Now, granted,
the next sentence says:
"This gives the objects in the nib file an opportunity to do any extra setup
that they require before the user or the rest of the application attempts to
interact with them."
So this might be where you got them impression that it is called first, but
actually this just means, in effect, that it is called before any of your
other code gets a crack at any of the nib objects, but as you can see from
reading the entire paragraph, everything gets initialized _before_ the
awakeFromNib call, and almost any object method could potentially be called
in the process of initialization.
- Dennis D.
[Note: quoted material is Copyright (c) 2001 O'Reilly & Associates, Inc.]