Re: NSArrayController and threading
Re: NSArrayController and threading
- Subject: Re: NSArrayController and threading
- From: "John C. Randolph" <email@hidden>
- Date: Wed, 22 Dec 2004 15:16:17 -0800
On Dec 22, 2004, at 1:27 PM, Joe Chan wrote:
After some experiments I found the following interesting facts:
- In order for changes to occur, -willChangeValueForKey: is definitely
needed.
- For some reason -didChange:valuesAtindexes:forKey: doesn't work, but
-didChangeValueForKey: does.
My model objects roughly look like this:
@interface Record : NSObject
{
NSMutableDictionary *_data;
Don't use a leading underscore for the names of any ivars or methods.
All the ivar names in the framework start with an underscore, so
there's a considerable hazard of a name collision.
}
...
- (void)loadThumbnail; // called within the thread to load the image
- (NSImage*)thumbnail; // return some default image if not loaded yet
@end
@interface Document : NSDocument
{
NSMutableArray *_recordList;
}
- (NSMutableArray*)recordList;
- (void)startLoadFiles;
- (void)loadFiles;
- (void)fileLoaded: (NSIndexSet *) indexes;
@endif
Inside fileLoaded:, I have to do something like this:
- (void)fileLoaded: (NSIndexSet *) indexes
{
Record *rec = [_recordList objectAtIndex: [indexes firstIndex]];
[rec willChangeValueForKey: @"thumbnail"];
[rec didChangeValueForKey: @"thumbnail"];
/* This doesn't work
[self willChange: NSKeyValueChangeReplacement
valuesAtIndexes:indexes forKey:@"thumbnail"];
[self didChange: NSKeyValueChangeReplacement
valuesAtIndexes:indexes forKey:@"thumbnail"];
*/
}
Which seems very strange to me. Is this a bug in the binding stuff, or
am I not understanding willChange:valuesAtIndexes:forKey: right?
Could be a bug in bindings, but I'd need to see a test case to be
sure.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden