On Aug 10, 2008, at 10:03 AM, Kyle Sluder wrote:

On Sat, Aug 9, 2008 at 8:54 PM, James Gorham <[EMAIL PROTECTED]> wrote:
I think that's where I'm unclear. Making the Document class aware of the view is easy enough with an IBOutlet. But how to properly make the view
aware of the document I'm unsure of.

You're missing the point.  You don't connect your NSDocument (model)
to your views, you have a controller in between.  This controller is
responsible for noticing/being notified when the document changes so
it can update the view, and it is also responsible for noticing/being
notified when the view changes so it can update the document.

Understood. For such an example, it seemed like creating a dedicated controller was a bit overkill, while not adhering strictly to MVC.

I ended up making the custom view an outlet in the document, and setting a pointer to the document as an ivar in the view. During redraw, the view requests the list of objects from the NSDocument. When new objects are added, the view messages the document to add them to the collection.

It looks like the line of code from Dave Carrigan could have solved it pretty easily as well, without requiring the NSDocument ivar.

id doc = [[[self window] windowController] document]

So yes, the document does end up acting as both the controller and model, but it works well enough for this simple application.

Thanks to all for their input, it was helpful in both achieving the solution and increasing my understanding.

-James

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to