Talk About Network

Google





Mac > Mac Programmer Help > Re: Help with D...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 3712 of 3889
Post > Topic >>

Re: Help with Delegates and File's Owner

by Sherman Pendley <spamtrap@[EMAIL PROTECTED] > Apr 19, 2008 at 04:12 PM

Cory <cory.imdieke@[EMAIL PROTECTED]
> writes:

> Hello, I'm a new Mac App Programmer used to Java and a little bit of C+
> +, and I'm trying to wrap my mind around Delegates. How do they work,
> what are they for, etc?

Apple says it far better than I could:

   
<http://developer.apple.com/do***entation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_4.html>

> The other basic concept that I'm not too firm on is the File's Owner
> in a nib file. What exactly does it point to, and what defines what it
> is?

Nibs are loaded by methods like NSWindowController's
-initWithWindowNibName:owner:, and as the name of the method implies, the
owner is passed as a parameter when this method is called. If the method
-initWithWindowNibName: is used instead, it simply calls the first method,
passing itself as the owner.

> If I open another window from a method in my AppController with a
> button in my Main nib file, is the new window's File's Owner my
> AppController, or the window that called the method in the
> AppController?

That depends on how you create the NSWindowController instance. You can
let it assume owner****p of the nib, or you can assign an owner object of
your choice.

> What's the Owner of the Main nib?

NSApp, the global NSApplication singleton. NSApplicationMain(), called
from
main(), p***** NSApp as the owner to -initWithWindowNibName:owner: to load
the MainMenu.nib.

> I have a alright idea of Outlets and so on, basically a way to access
> an object instance in a nib file from code, is that the basic idea?

Yeah, pretty much. When a nib is loaded, an object graph is deserialized
from the .nib bundle. Outlets are pointers to some of those objects, and
the nib loading machinery will attempt to resolve those pointers after
the objects have been deserialized. To do so, it will look for a -setFoo:
accessor method first, then for instance variables - if it fails to find
either of those in the nib's owner object, it will NSLog() a complaint.

Note that outlet resolution isn't fully KVC compliant - it doesn't go
through setValue:forKey:, it takes the above steps on its own.

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
 




 4 Posts in Topic:
Help with Delegates and File's Owner
Cory <cory.imdieke@[EM  2008-04-18 20:42:46 
Re: Help with Delegates and File's Owner
David Phillip Oster <o  2008-04-19 11:44:30 
Re: Help with Delegates and File's Owner
Sherman Pendley <spamt  2008-04-19 16:12:17 
Re: Help with Delegates and File's Owner
Cory <cory.imdieke@[EM  2008-04-19 22:27:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 19:02:47 PST 2009.