While sometimes you simply have no choice but to loop through your windows, it isn't the first approach that comes to mind for this.

In the MVC design, you have separate views (one in each document) and separate controllers (each one referenced from each document 1:1) but what you do need is a single common data model that all of these controllers are referencing. Since this is common to all, it is a good choice for a singleton.

Then, when any view, via the controller, updates the model, all the other controllers get informed about the change (via KVO, bindings, notifications, whatever) and update their views accordingly. You should not need to loop through your windows and try and force an update, that's just trying to work around the MVC design instead of making proper use of it.

The singleton will have to be external to the nib since there is not one instance per doc, but one instance per app, and you'll have to make that connection as each nib is loaded. From then on, however the updates notifications are actually implemented, it will work correctly without further intervention on your part. If you find yourself thinking you need to manage collections of things yourself just to handle this sort of update notifications, chances are you've overlooked something obvious, since there are numerous built-in mechanisms available for handling just this, and very elegantly too.

--Graham



On 28/09/2009, at 4:19 AM, jon wrote:

ok, after thinking and analyzing what was going on, everytime i make a new document in the running app, it created a new instance of the window and all related stuff in the window including myOutlineView. and then my dataSource in code remained the same that fills out these outline views... (atleast this is my current understanding).

so my question now morphs into:

as Jens says below, he in some cases is looping through the apps window list...

in my case, in my main document xib, i have an "outline Controller" which is type NStreeController... and i have this defined..

IBOutlet NSTreeController *treeController which is the thing that is controlling the outline view, and appears to be the thing i want to update...

the question it appears to me is: that this "treeController" also is made into multiple instances with each new Document, is there an already defined "loop" of these? (a list of the open document's NSTreeController *treeController;)

or do i need to make an NSMutableArray, and keep track of these myself? and then update these instances myself by looping through them?


_______________________________________________

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 arch...@mail-archive.com

Reply via email to