Re: Troubles with CollectionView and IKImageBrowserView
Re: Troubles with CollectionView and IKImageBrowserView
- Subject: Re: Troubles with CollectionView and IKImageBrowserView
- From: Daniel Vollmer <email@hidden>
- Date: Thu, 12 Jun 2008 09:19:48 +0200
On Jun 12, 2008, at 00:25, Jens Alfke wrote:
On 11 Jun '08, at 1:14 PM, Manuel wrote:
But the IKImageBrowserView doesn't call these methods. I setup a
testmethod in the MYNSCollectionViewItem like the following code,
to verify that the imagebrowser outlet is set and to set again the
datasource:
Hm, I don't have any exact ideas, but I wonder if something's going
wrong because CollectionViewItems get copied. (The one you wire up
in the nib is a prototype, and the view makes a copy of it for every
item it needs.) Perhaps the item is getting set as the image-
browser's data source before the copy, so the instance being
displayed isn't actually the one that's the data source?
Jens is right in that copying the collection view is often a problem,
as NSView does not support the NSCopying protocol. There's some more
information on the way that NSCollectionView copies the view here:http://www.cocoadev.com/index.pl?NSCollectionView
(near the bottom).
I got it working like this:
- put your custom view initialisation in initWithCoder: (as that is
the one used to copy the original instance / unarchive your nib)
- in your view, have an IBOutlet that's connected to the
NSCollectionViewItem instance (called cvItem in my case)
- in awakeFromNib bind the properties you're interested in (as these
get restored / set correctly in the cloning process), e.g.
- (void)awakeFromNib
{
[self bind:@"plotRoot" toObject:cvItem
withKeyPath:@"representedObject" options:nil];
[self bind:@"isSelected" toObject:cvItem withKeyPath:@"selected"
options:nil];
}
This setup works fine for me (ignoring the other known bugs and
documentation deficiencies of NSCollectionView — it's slightly
disheartening when you file a bug on it, get a dup back and realise
it's been known long enough for 1094954 other bugs to be filled..).
HTH,
Daniel._______________________________________________
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