• 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: NSArrayController and threading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArrayController and threading


  • Subject: Re: NSArrayController and threading
  • From: Joe Chan <email@hidden>
  • Date: Wed, 22 Dec 2004 16:27:25 -0500

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;
}
...
- (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?

On Dec 22, 2004, at 4:08 PM, John C. Randolph wrote:


On Dec 22, 2004, at 6:29 AM, Joe Chan wrote:



This approach is much simpler than my initial guess. The loading of thumbnail works, however, the table is not getting updated with the thumbnails until I scroll. Unfortunately, because binding eliminated almost all the glue code, it also makes it very hard to debug why it's not getting updated. I thought that once the didChange: is called, the NSArrayController will trigger an update on the NSImageCell and should redraw itself.

Hmm.. I wrote the code off the top of my head, and haven't tested it in an app. You might try sending -willChangeValueForKey: before -didChange:valuesAtIndexes:forKey:.




-jcr





John C. Randolph <email@hidden> (408) 974-8819 Sr. Cocoa Software Engineer, Apple Worldwide Developer Relations http://developer.apple.com/cocoa/index.html



--
Joe Chan
Sun Microsystems, Inc.
Burlington, MA
Tel: (781) 442-0809

_______________________________________________
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


  • Follow-Ups:
    • Re: NSArrayController and threading
      • From: mmalcolm crawford <email@hidden>
    • Re: NSArrayController and threading
      • From: "John C. Randolph" <email@hidden>
    • Re: NSArrayController and threading
      • From: Scott Stevenson <email@hidden>
References: 
 >NSArrayController and threading (From: Joe Chan <email@hidden>)
 >Re: NSArrayController and threading (From: "John C. Randolph" <email@hidden>)
 >Re: NSArrayController and threading (From: Joe Chan <email@hidden>)
 >Re: NSArrayController and threading (From: "John C. Randolph" <email@hidden>)

  • Prev by Date: Re: NSArrayController and threading
  • Next by Date: Re: NSArrayController and threading
  • Previous by thread: Re: NSArrayController and threading
  • Next by thread: Re: NSArrayController and threading
  • Index(es):
    • Date
    • Thread