-->

How do I bind an NSTextField's value to an NSO

2019-04-09 15:07发布

问题:

I have a pretty simple set up here, and Xcode is giving me a comment-less red "!" mark in the interface builder.

Started from a Core Data-based document template. The document xib has an NSObjectController instance, whose Managed Object Context is bound to the File's Owner (my NSPersistentDocument subclass). An NSTextField is present, whose Value I want to bind to the NSObjectController...and this is where the problem comes in.

I type "title" for the "Model Key Path," because that's the correct property for my NSManagedObject, which should appear in the text field. When I click into the empty Controller Key field, the autocompletion bizarrely suggests fields that are only for NSArrayController:

Any time I try to type "content" as the Controller Key (because that's the correct property for an NSObjectController) and then hit Tab/Return/whatever, the "content" is shifted down to the Model Key Path, like so:

What is this red exclamation mark for? When I leave "Controller Key" empty and "Model Key Path" as content.title, the app works. The binding is correct and reflects the "title" property of my NSManagedObject. I am absolutely sure that "Object Controller" is an instance of NSObjectController.

回答1:

Use "selection". For an NSObjectController, the selection is the content object.