• 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
Re: Grief with NSDocument windowControllerDidLoadNib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grief with NSDocument windowControllerDidLoadNib


  • Subject: Re: Grief with NSDocument windowControllerDidLoadNib
  • From: Brian Webster <email@hidden>
  • Date: Thu, 28 Mar 2002 09:27:08 -0600

On Thursday, March 28, 2002, at 08:08 AM, Ken Tabb wrote:

The reason I don't think it's elegant is because the document loads the image and makes an NSImage from it, but there is a break while the window controller subclass loads and sets up the nib. What the above seems to be suggesting is that the window controller then (in its windowDidLoad method) asks the document for the image. This assumes the window controller knows about the document class.

Well, yes, it does know about the document object. The -[NSWindowController document] method is there for the calling.

I thought the whole point of MVC was that the window controller knew nothing about the document, just how to display things. In other words it shouldn't know where to get the things which need displaying, they should be provided to it. As the document owns the window controller, I would have thought it would make more sense to get the document to give the window controller the NSImage rather than get the window controller to (implicitly know about and) ask the document for the NSImage.

In terms of MVC, both NSDocument and NSWindowController fall into the controller category. You can think of it as the NSDocument being the model controller and the NSWindowController being the view controller. NSWindowController is handy because you can have one subclass for each window in your interface, rather than having to deal with all the windows with one NSDocument object.

One option you have would be to have your windowDidLoadNib simply call [[self document] windowControllerDidLoadNib:self] and have the NSDocument handle it from there. You still have to call a method on the document, but that would at least make it sort of generalized so that you would be changing your NSDocument rather than your NSWindowController if your data model changes in the future.

Also, I think one reason that they've implemented it this way is so that it's possible to use NSWindowController without an NSDocument, just as a convenient way to manage a single window. That's why the window controller is notified of the nib loading rather than the document, which could potentially not exist. However, since you know your subclass of NSWindowController is in the context of a document based app, passing some stuff on to the document makes perfect sense.

--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Grief with NSDocument windowControllerDidLoadNib (From: Ken Tabb <email@hidden>)

  • Prev by Date: Re: check out the spreadsheet control! and NSTextViewCell Overlapping its bounds
  • Next by Date: Re: EOF (was [objC retain];
  • Previous by thread: Re: Grief with NSDocument windowControllerDidLoadNib
  • Next by thread: Getting dimensions of an NSImageView's frame style?
  • Index(es):
    • Date
    • Thread