Re: NSCollectionView questions
Re: NSCollectionView questions
- Subject: Re: NSCollectionView questions
- From: "Carter R. Harrison" <email@hidden>
- Date: Fri, 8 Feb 2008 18:54:28 -0500
I've finally had a chance to play around with NSCollectionView--pretty
handy, but a few things are still giving me trouble:
As far as I can tell, IBOutlet connections from collection item
subclasses or the prototype view aren't preserved. NSControl target/
action links from the prototype view's contents to the collection item
DO work, which makes me think I need to do something in copyWithZone
or the like, but I haven't found the right magic. The only workaround
I've been able to come up with is giving the view a reference to the
collection item in setRepresentedObject:, then the view's contents can
get at the item through their superview. Ick.
I'm loading some 3,000 items into the list, and it's pretty slow.
Sampler says that the first third or so of that is setting up bindings
for the copied views. In this case the underlying data won't be
changing, so I could set up the views by hand in the collection item's
setRepresentedObject: method--but not without those IBOutlet
connections.. (The middle third is looking for button cells or
something, -[NSView _recursiveFindDefaultButtonCell]. Out of my hands,
I'd guess, if I want to have a button in the view.) The last third
appears to be setting up the animation, which I really don't need in
this case (or even notice--the contents appear instantly). Is this
avoidable?
Another odd thing I've noticed is that adding an item to the model
array causes the entire collection view to reload. (And at first, I
was using [[self mutableArrayValueForKey:@"items"]
addObjectsFromArray:] which appears to insert the objects one by one
instead of in a batch: adding 3,000 items would allocate around 4.5
million views!) I'd like to prepare data on a worker thread and feed
it in batches to the main thread to display in the collection view,
but this isn't really feasible if the view rebuilds itself from
scratch every time. Is that how it's supposed to work? Or have I
bungled something up?
I had the same problem when I was working with the NSCollectionView.
My NSCollectionView was representing an entity from my managed object
model. When I started adding a lot of objects to the model it was
extremely slow due to the fact that the collectionview was reloading
data each time a new managed object was added to the context. What I
did was use the [self mutableArrayValueForKey:@"items"] method just as
you did to produce a mutable array. I then added my objects to a
temporary array. When I was done adding them I simply copied the
contents of my temporary array into the array returned by the
mutableArrayValueForKey method. This made things run much faster and
use far less memory and CPU while adding the objects to the context.
Not sure how applicable this solution would be for your application
however. Hope this gets to you ok, I couldn't figure out how to
easily reply to your thread since i subscribe to the digest only.
Thanks!
-Dave
Panic, Inc.
_______________________________________________
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