Re: [iPhone] Nib Loading Question
Re: [iPhone] Nib Loading Question
- Subject: Re: [iPhone] Nib Loading Question
- From: Matt Neuburg <email@hidden>
- Date: Sat, 31 Jul 2010 09:44:42 -0700
- Thread-topic: [iPhone] Nib Loading Question
On Sat, 31 Jul 2010 09:39:12 -0500, Fritz Anderson <email@hidden>
said:
>There are three ways to access the contents of a NIB.
>
>1. Via -[UIViewController initWithNibName:bundle:], which connects the
references to outlets in File's Owner (the view controller itself). If a root
object in the NIB doesn't have a link to the owner's outlet, that object is
adrift and goes away at the next autorelease drain.
>
>2. Via -[NSBundle loadNibNamed:owner:options:], you specify an owner object,
which again gets its IBOutlets filled in from links to File's Owner in the NIB.
No link, no object.
>
>3. By taking the NSArray returned by -[NSBundle loadNibNamed:owner:options:],
usually with owner: set to nil (though that's not required). The array contains
all the root objects in the NIB.
Let's simplify for a beginner, concentrating only on how the nib's top-level
objects are accessed, and for a moment ignoring the question of how the nib
gets loaded in the first place.
There are *two* ways to access to the top-level objects of a nib: either
through the NSArray returned by -[NSBundle loadNibNamed:owner:options:], or
through a chain of outlets rooted in the instance that owns the nib at the
time it loads (represented in the nib by the file's owner proxy). You (the
beginner) will almost certainly use the latter. Back your outlets by a
retain-policy setter (typically thru a property and synthesized accessors),
since otherwise the loaded object will vanish in a puff of smoke and you'll
crash when you send a message to a dangling pointer. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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