Re: Connect NSView to NSDocument
Re: Connect NSView to NSDocument
- Subject: Re: Connect NSView to NSDocument
- From: James Bucanek <email@hidden>
- Date: Sat, 4 Mar 2006 16:19:02 -0700
Jason Barker wrote on Saturday, March 4, 2006:
>I have a Cocoa Document-based Application project with a MyDocument
>class and a subclass of NSView in my MyDocument.nib. I have some
>objects in my MyDocument class that I would like my subclass of
>NSView to be able to access. How can I do this? Do I have to set up a
>connection between these objects in Interface Builder or through Xcode?
You need to add an outlet to your custom that you then set in Interface Builder.
In your subclass of NSView, simply define an outlet that points to your document object:
@interface MyView : NSView
{
@public
IBOutlet MyDocument* document;
...
Import this class into IB then connect the document outlet in your instance of MyView to your instance of MyDocument. When the NIB is loaded, the AppKit framework will set the MyDocument* pointer in your MyView object to the instance of MyDocument. Now, any of the methods in MyView can (indirectly) access whatever they need in MyDocument.
[ Note: Don't count on the connection to be set until the NIB has finished loading. ]
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden