How do I bind an NSTextField's value to an NSObjectController's content without errors?

£可爱£侵袭症+ 提交于 2019-12-06 04:04:38

问题


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.



来源:https://stackoverflow.com/questions/10691287/how-do-i-bind-an-nstextfields-value-to-an-nsobjectcontrollers-content-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!