Re: Is cascading Nib Loading from -awakeFromNib permissible?
Re: Is cascading Nib Loading from -awakeFromNib permissible?
- Subject: Re: Is cascading Nib Loading from -awakeFromNib permissible?
- From: Stuart Malin <email@hidden>
- Date: Wed, 11 Mar 2009 13:37:35 -1000
On Mar 11, 2009, at 1:03 PM, Ken Thomases wrote:
On Mar 11, 2009, at 5:49 PM, Stuart Malin wrote:
I am getting infinite calls, not double calls.
It sounds to me like you're getting double calls and you're turning
them into infinite calls. If you load a nib inside of -
awakeFromNib, and you don't guard against being called again, you'll
load the nib again, get -awakeFromNib again, load the nib again, ...
infinitely.
Ah, sure enough, because that re-invocation of my -awakeFromNib then
invoked -loadNibNamed: which gets a circular mess in motion.
My apologies to you, Dave, for not realizing this "double" call was in
fact the issue.
Further, the second Nib I am loading has no references back to the
controller, except as File's Owner.
And that's enough to get awakeFromNib'd.
From the documentation for the awakeFromNib method:
"It is recommended that you maintain a one-to-one correspondence
between your File’s Owner objects and their associated nib files.
Loading two nib files with the same File’s Owner object causes that
object’s awakeFromNib method being called twice, which could cause
some data structures to be reinitialized in undesired ways. It is
also recommended that you avoid loading other nib files from your
awakeFromNib method implementation."
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSNibAwaking_Protocol/Reference/Reference.html
So, you're going against Apple's recommendation in two ways.
Sseems so.
In regard to the first recommendation I am going against (one-to-one
correspondence):
Interesting -- there must be some further distinctions here. I have
another controller, not instantiated by being included in a Nib file,
but by alloc & init. This controller manages an ensemble of entities
that are each loaded from (distinct) Nib files. This controller
receives no calls to an -awakeFromNib method (I didn't have one there,
but just put one there to see if it would receive calls for each Nib
loaded). So, this scenario of receiving -awakeFromNib calls as a
consequence of being some loaded nib's File's Owner seems to depend on
just how the object invoking -loadNibNamed: was itslef invoked.
btw: I know that the IBOutlets in the controller associated with
File's Owner that are linked in IB to objects there get over-written
on loading of each Nib file. After loading each Nib, I copy the outlet
values that I need, storing them in collection objects (happen to be
using dictionaries). This controller works just fine, and handling
the architecture this way allows me to have distinct Nibs rather than
one rather cluttered Nib, (as each of the distinct Nibs has views and
controllers of its own), yet all are managed by one in the same
controller.
In regards to the second recommendation I am going against (avoid
loading nib files from awakeFromNib)):
This is worded as a "recommendation" so, I'm presuming that if
properly handled to avoid recursion and multiple initializations, then
this is otherwise safe.
I'm going to continue down this path as architecturally it works for
me. I appreciate the quick replies, and the comments made do alert me
to the effects I need to design around. Thanks again.
_______________________________________________
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