Skip navigation.
 
mlRe: NSCollectionView caching
FROM : Christiaan Hofman
DATE : Sat May 10 17:47:29 2008

On 10 May 2008, at 5:16 PM, Georg Seifert wrote:

> Hello,
>
> I use a NSCollectionView. The itemPrototype contains a NSImageView 
> and two text fields.
>
> I bind to a NSArrayController (wich controlles a array of custom 
> objects with properties for an NSImage and some NSStrings).
> This Controller is filtered with predicates. Every time I remove the 
> predicate, the collection view will generate all the item views 
> again and even with 200 entries this is awfully slow (on my 
> PowerBook 1.67GHz).
>
> How I can save the item views and just hide/reuse them? Or is there 
> any other way to speed things up?
>
> Thanks
> Georg


I think you should override -newItemForRepresentedObject:. However the 
caching logic (e.g. when to dispose of them) could depend on your 
exact model.

In a similar situation (displaying views in a table in a Tiger-
compatible app) I had a view contained by the represented object. This 
makes it easy to have unique items, and they are properly disposed of 
when the object gets removed. You could do something like this:

- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
   id item = [object item];
   if (item == nil) {
       item = [super newItemForRepresentedObject:object];
       [object setItem:item];
   } else {
       [item retain];
   }
   return item;
}

Warning: beware for retainment cycles if you're not careful.

Christiaan

Related mailsAuthorDate
mlNSCollectionView caching Georg Seifert May 10, 17:16
mlRe: NSCollectionView caching Christiaan Hofman May 10, 17:47