NSCollectionView questions
-
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?
Thanks!
-Dave
Panic, Inc. -
On Feb 6, 2008, at 2:07 PM, Dave Hayden wrote:> I've finally had a chance to play around with NSCollectionView--
> pretty handy, but a few things are still giving me trouble: [...]
Alright, I'll go send these to bugreporter..
-D -
> 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. -
I needed to put a pop up menu inside a view of a NSCollectionViewItem,
then customize the contents of the menu using the representedObject.
I subclassed NSCollectionViewItem and augmented setView to cause
"self" to be the delegate of the NSPopUpButton menu, obtained with
[view ViewWithTag:n].
That subclass has a method for MenuNeedsUpdate which passes the
message to its NSCollectionView along with a copy of the
representedObject.
My subclass of NSCollectionView has an IBOutlet for the Window
Controller, so it can pass the message there where the menu can be
customized.
Hope that helps,
DC
On Feb 11, 2008, at 2:19 PM, Dave Hayden wrote:> On Feb 9, 2008, at 6:21 AM, David Carlisle wrote:
>
>> I don't understand exactly what you are trying to do, but your
>> workaround sounds more complicated that the ones I am using.
>
> If I subclass the view used for the collection view items and put
> IBOutlets in those views, the references aren't retained when the
> item views are created. So I can't reference the subviews of that
> view by linking them with outlets and I can't get a reference from
> the view to the item controller object.
>
> Can you describe your workaround?
>
> Many thanks,
> -Dave
> -
Does subclassing NSCollectionView and NSCollectionViewItem make things
easier, or is it a necessity?
Adhamh
On Feb 11, 2008, at 4:59 PM, David Carlisle wrote:> I needed to put a pop up menu inside a view of a
> NSCollectionViewItem, then customize the contents of the menu using
> the representedObject.
>
> I subclassed NSCollectionViewItem and augmented setView to cause
> "self" to be the delegate of the NSPopUpButton menu, obtained with
> [view ViewWithTag:n].
>
> That subclass has a method for MenuNeedsUpdate which passes the
> message to its NSCollectionView along with a copy of the
> representedObject.
>
> My subclass of NSCollectionView has an IBOutlet for the Window
> Controller, so it can pass the message there where the menu can be
> customized.
>
> Hope that helps,
> DC
>
> On Feb 11, 2008, at 2:19 PM, Dave Hayden wrote:
>
>> On Feb 9, 2008, at 6:21 AM, David Carlisle wrote:
>>
>>> I don't understand exactly what you are trying to do, but your
>>> workaround sounds more complicated that the ones I am using.
>>
>> If I subclass the view used for the collection view items and put
>> IBOutlets in those views, the references aren't retained when the
>> item views are created. So I can't reference the subviews of that
>> view by linking them with outlets and I can't get a reference from
>> the view to the item controller object.
>>
>> Can you describe your workaround?
>>
>> Many thanks,
>> -Dave
>> -
I didn't find another way to get the clicked menu item and the
represented object into a method in the window controller for updating
the menu.
On Feb 11, 2008, at 4:15 PM, Adhamh Findlay wrote:> Does subclassing NSCollectionView and NSCollectionViewItem make
> things easier, or is it a necessity?
>
> Adhamh
>
> On Feb 11, 2008, at 4:59 PM, David Carlisle wrote:
>
>> I needed to put a pop up menu inside a view of a
>> NSCollectionViewItem, then customize the contents of the menu using
>> the representedObject.
>>
>> I subclassed NSCollectionViewItem and augmented setView to cause
>> "self" to be the delegate of the NSPopUpButton menu, obtained with
>> [view ViewWithTag:n].
>>
>> That subclass has a method for MenuNeedsUpdate which passes the
>> message to its NSCollectionView along with a copy of the
>> representedObject.
>>
>> My subclass of NSCollectionView has an IBOutlet for the Window
>> Controller, so it can pass the message there where the menu can be
>> customized.
>>
>> Hope that helps,
>> DC
>>
>> On Feb 11, 2008, at 2:19 PM, Dave Hayden wrote:
>>
>>> On Feb 9, 2008, at 6:21 AM, David Carlisle wrote:
>>>
>>>> I don't understand exactly what you are trying to do, but your
>>>> workaround sounds more complicated that the ones I am using.
>>>
>>> If I subclass the view used for the collection view items and put
>>> IBOutlets in those views, the references aren't retained when the
>>> item views are created. So I can't reference the subviews of that
>>> view by linking them with outlets and I can't get a reference from
>>> the view to the item controller object.
>>>
>>> Can you describe your workaround?
>>>
>>> Many thanks,
>>> -Dave
>>> -
On Feb 11, 2008, at 2:59 PM, David Carlisle wrote:> I needed to put a pop up menu inside a view of a
> NSCollectionViewItem, then customize the contents of the menu using
> the representedObject.
>
> I subclassed NSCollectionViewItem and augmented setView to cause
> "self" to be the delegate of the NSPopUpButton menu, obtained with
> [view ViewWithTag:n].
Ah, that's funny--I've never noticed -[NSView viewWithTag:] before.
Seems kind of hacky, but yeah, that would work. Thanks for the tip!
-Dave
Panic, Inc. -
You can set the tag in Interface Builder for NSPopUpButton and
NSTextField, but in one case I needed to get an NSBox subview so I
could manually bind to its fillColor. You cannot set a tag for NSBox
in Interface Builder, so I needed to create a subclass, then override
the tag method to return the tag number I was looking for.
DC
On Feb 12, 2008, at 3:02 PM, Dave Hayden wrote:> On Feb 11, 2008, at 2:59 PM, David Carlisle wrote:
>
>> I needed to put a pop up menu inside a view of a
>> NSCollectionViewItem, then customize the contents of the menu using
>> the representedObject.
>>
>> I subclassed NSCollectionViewItem and augmented setView to cause
>> "self" to be the delegate of the NSPopUpButton menu, obtained with
>> [view ViewWithTag:n].
>
> Ah, that's funny--I've never noticed -[NSView viewWithTag:] before.
> Seems kind of hacky, but yeah, that would work. Thanks for the tip!
>
> -Dave
> Panic, Inc.


