Re: NSArrayController Frustration
Re: NSArrayController Frustration
- Subject: Re: NSArrayController Frustration
- From: David Carlisle <email@hidden>
- Date: Tue, 27 Nov 2007 00:14:23 -0700
On Nov 25, 2007, at 10:30 PM, Steve Weller wrote:
I am expecting that when I do [docArray addObject:x] that the
array controller will observe the change and do a reloadData on
the NSTableView. That isn't happening.
Your expectation is incorrect. What your NSArrayController is
bound to is not the docArray *object* but the docArray *property*
(or key) of your NSWindowController subclass.
Thanks to everybody for the suggestions. It helps to know what to
look for in the documentation.
My docArray actually resides in another object called globalObject, so
I bound the NSArrayController to the NSWindowController at
keyPath:@"globalObject.docArray". The NSWindowController has an
accessor method for globalObject. Then using the suggested method #2,
I replaced operations on docArray in globalObject with operations on
[self mutableArrayValueForKey:@"docArray"]. That seems to have
solved the problem.
But it might not work correctly in a multithreaded environment. The
NSWindowController may come and go asynchronously while other threads
may be adding or removing objects from docArray, so I am binding and
unbinding the NSArrayController contentArray manually in globalObject
within the same lock that restricts adding and removing objects from
docArray. This is intended to control the way that NSArrayController
adds and removes observers from each document in docArray so that
everything remains consistent.
But when I NSLog the way NSArrayController creates and removes
observers for each document, it is not occurring as neatly as I had
expected. Sometimes the log shows that NSArrayController adds
observers to documents in docArray after the bind method has returned
and the lock has been unlocked. It also creates and removes observers
much more often than I had expected.
It will probably become apparent later if this is a cause for concern.
_______________________________________________
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