Please help figure out the binding for NSCollectionView
I have 开发者_高级运维a custom NSView (MyView), which is rendered by the NSViewCollectionItem.
MyView has a property of type MyObject.
My main NSWindowController has IBOutlets to NSViewCollection and NSArrayController.
NSArrayController is bound to an array of objects of type MyObject.
I'd like to have the values from the array to be bound to "myView.myObject" path.
I can't figure out how to set this up in IB. I don't understand which keys I should be using. Should my array be a collection of NSDictionary objects instead, so that I can have a key named "myObject" rather than storing the values directly?
I'm very new to bindings, so it's a bit of a struggle. Please help.
I sorted it out. It should go like this:
1) NSArrayController:
Bind to → MyWindowController (File's Owner)
Model Key Path → myArrayWithObjects
2) NSCollectionView:
Bind to → NSArrayController
Controller Key → arrangedObjects
3) Now, to get that value from the array into the custom NSView, you'd need to override the following method in your NSCollectionViewItem subclass:
- (void)setRepresentedObject:(id)object
{
[super setRepresentedObject:object];
// e.g. [self.view setMyProperty:object];
}
You could bind "myView.myObject" to "representedObject.property" of NSCollectionViewItem. So if you had a property named info on your arrangedObject, you could bind an object to representedObject.info
精彩评论