• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to reference a NSDocument from a NSView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to reference a NSDocument from a NSView?


  • Subject: How to reference a NSDocument from a NSView?
  • From: "Jeff Mesnil" <email@hidden>
  • Date: Tue, 19 Aug 2008 13:37:59 +0200

Hi,

I'm currently learning Cocoa by reading the 3rd edition of "Cocoa
Programming for Mac OS X".
One of the excercise is to create an application to draw ovals.

I ended up with a project like this:
DrawView is a subclass of NSView which is responsible to draw the ovals
MyDocument is a subclass of NSDocuments which holds a NSMutableArray
of ovals + code to load/save the files

I then created an IBoutlet theDoc in DrawView.h to reference the
instance of MyDocument by connecting the File's Owner.
In DrawView, when the user creates an oval (by creating a NSRect with
the mouse), it calls [theDoc addOval:oval].
And in its -drawRect:, it asks the doc for an array of ovals to draw them.

The application is behaving as expected, the model (the ovals) are
kept in MyDocument and the DrawView just draws them.
But I was wondering if that was the "right" Cocoa way to do so, to use
an IBOutlet to connect a NSView to a NSDocument.
Is there another way to have a reference to the document from one view
of the application?

regards,
jeff

--
Jeff Mesnil
email@hidden
http://jmesnil.net/weblog/
_______________________________________________

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

  • Follow-Ups:
    • Re: How to reference a NSDocument from a NSView?
      • From: "Jeff Mesnil" <email@hidden>
  • Prev by Date: Re: Subclassing NSArrayController?
  • Next by Date: Re: best way to determine if portion of window is visible?
  • Previous by thread: Re: Subclassing NSArrayController?
  • Next by thread: Re: How to reference a NSDocument from a NSView?
  • Index(es):
    • Date
    • Thread