简体   繁体   English

如何将NSTextField的值绑定到NSObjectController的内容而不会出现错误?

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

I have a pretty simple set up here, and Xcode is giving me a comment-less red "!" 我在这里有一个非常简单的设置,Xcode给了我一个没有评论的红色“!” 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). 文档xib有一个NSObjectController实例,其托管对象上下文绑定到文件的所有者(我的NSPersistentDocument子类)。 An NSTextField is present, whose Value I want to bind to the NSObjectController...and this is where the problem comes in. 存在NSTextField,其值我想绑定到NSObjectController ......这就是问题所在。

I type "title" for the "Model Key Path," because that's the correct property for my NSManagedObject, which should appear in the text field. 我为“模型键路径”键入“title”,因为这是我的NSManagedObject的正确属性,它应出现在文本字段中。 When I click into the empty Controller Key field, the autocompletion bizarrely suggests fields that are only for NSArrayController : 当我点击空的Controller Key字段时,autocompletion奇怪地建议仅用于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: 每当我尝试输入“content”作为Controller Key(因为这是NSObjectController的正确属性)然后点击Tab / Return / what时,“content”会向下移动到Model Key Path,如下所示:

错误的屏幕截图

What is this red exclamation mark for? 这个红色感叹号是什么? When I leave "Controller Key" empty and "Model Key Path" as content.title, the app works. 当我将“Controller Key”留空并且“Model Key Path”作为content.title时,应用程序正常工作。 The binding is correct and reflects the "title" property of my NSManagedObject. 绑定是正确的,并反映了我的NSManagedObject的“title”属性。 I am absolutely sure that "Object Controller" is an instance of NSObjectController. 我绝对相信“对象控制器”是NSObjectController的一个实例。

Use "selection". 使用“选择”。 For an NSObjectController , the selection is the content object. 对于NSObjectController ,选择是内容对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是NSObjectController的选择? - What is an NSObjectController's selection? 将NSTextField的文本颜色绑定到NSColorWell? - Bind NSTextField's text color to NSColorWell? 如何检测 NSTextField 何时具有焦点或它的内容是否选择了可可 - How to detect when NSTextField has the focus or is it's content selected cocoa 如何绘制看起来像Finder的文件名标签的NSTextField背景效果? - How do I draw an NSTextField background effect that looks like the Finder's file name label? NSTextField如何知道其值已更改? - How does an NSTextField know that it's value has changed? 如何使用故事板将NSTextField中的文本绑定到控制器上的属性值? - How can I bind the text in a NSTextField to the value of a property on a controller using a storyboard? NSTextField和NSTextFieldCell有什么区别,我绑定到哪个? - What is the difference between NSTextField and NSTextFieldCell and to which do I bind? 如何从 Swift 4.2 中的共享 Dropbox 链接读取文本文件的内容(无需下载)? - How do I read a text-file's content from it's shared Dropbox link in Swift 4.2 (without downloading)? NSTextField 如何设置 NSAttributedString 的 TextStyle 属性 - NSTextField How to Set NSAttributedString's TextStyle property 根据内容长度修改 NSTextField 的字体大小 - Modifying an NSTextField's font size according to content length
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM