Re: How do I bind custom view properties to an NSCollectionViewItem?
Re: How do I bind custom view properties to an NSCollectionViewItem?
- Subject: Re: How do I bind custom view properties to an NSCollectionViewItem?
- From: Markus Spoettl <email@hidden>
- Date: Sun, 3 Jan 2010 15:32:33 +0100
On Jan 3, 2010, at 9:11 AM, Rick Mann wrote:
> In the example for NSCollectionView, they show binding text labels to the collection view item's represented object's properties. This is fine and makes sense.
>
> But my item view contains a custom view that needs access to the represented object in the NSCollectionViewItem. Since my custom view can't be bound within IB, I need to bind it programmatically. But I can't find the right place to do this. I tried doing it in awakeFromNib, with an outlet in my custom view to the NSCollectionViewItem, but it's sometimes nil (Currently I have data for two items, and the first time awakeFromNib is called, the item outlet is set, and the second time, it's not; not sure why).
>
> When does IB actually set the bindings specified in the nib? When can I add bind: calls and have access to both my view instance and the NSCollectionViewItem?
What you could do is sub-class the NSCollectionViewItem your collection view is using (you will set the NSCollectionViewItem's class in IB) and implement -setRepresentedObject: which is called the at the time it is created and assigned its corresponding object.
There you can access the view and represented object and do whatever you like with it.
- (void)setRepresentedObject:(id)object
{
[super setRepresentedObject:object];
MyView *myView = (MyView *)[self view];
// bind view properties to object here
}
An alternative would be sub-classing the NSCollectionView and implementing -newItemForRepresentedObject: where you too can get access to the ItemView and view for the object.
Regards
Markus
--
__________________________________________
Markus Spoettl
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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