与子视图和多发钞银行核心数据绑定 [英] Core Data bindings with subviews and multiple NIBs

查看:178
本文介绍了与子视图和多发钞银行核心数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于文档的核心数据的应用程序。我的主要核心数据实体有几个字符串字段,其中大部分是必然NSTextFields,但一个是绑定到一个NSTextView。

I have a document-based Core Data app. My main Core Data entity has several string fields, most of which are bound to NSTextFields, but one is bound to an NSTextView.

我使用视图切换(有多个视图控制器)技术作为核心提示书解释。我所有的子视图是由ManagedViewController,我N​​SViewController的子类,有一个managedObjectContext现场控制。

I am using the technique for view switching (with multiple view controllers) as explained in the Hillegass book. All of my subviews are controlled by a ManagedViewController, my subclass of NSViewController that has a managedObjectContext field.

我的子视图存在于一个单独的榫文件。出于某种原因,我在笔尖设置绑定不工作 - 但如果我在主nib文件中设立了完全相同的方式,窗口小部件和绑定相反,他们做工精细

My subview exists in a separate nib file. For some reason, the bindings I have set up in that nib are not working--but if I set up the widgets and the bindings in the exact same way in the main nib file instead, they work fine.

请参阅图:

在主nib文件,我有一棵树控制器,其managedObjectContext势必文件拥有者的MOC(文件的所有者是myDocument中)。该的NSTextField的值(是的,价值 - 它不是富文本)被绑定到treeController.selection.content(其中的内容是实体的字符串属性。)没问题。这工作得很好。

In the main nib file, I have a tree controller whose managedObjectContext is bound to File's Owner's mOC (File's Owner is MyDocument). The NSTextField's value (yes, value--it's not rich text) is bound to treeController.selection.content (where content is a string property of the entity.) No problem. This works fine.

在第二榫文件,我有另一棵树控制器,其managedObjectContext势必文件拥有者的MOC(文件的所有者是我ManagedViewController)。该的NSTextField的价值必然与上述相同的方法。

In the second nib file, I have another tree controller whose managedObjectContext is bound to File's Owner's mOC (File's Owner is my ManagedViewController). The NSTextField's value is bound the same way as above.

在我的code,我已经测试,以确保在两个managedObjectContexts指代相同的对象。他们这样做,这不是零。

In my code, I have tested to make sure that the two managedObjectContexts refer to the same object. They do, and it's not nil.

我没有得到一个错误 - 它只是值永远不会在子视图NSTextViews绑定。他们总是为零。

I don't get an error--it's just that the values never bind with NSTextViews in the subview. They're always nil.

另外,我已经试过NSTextFields - 同样的问题

Also, I have tried NSTextFields--same problem.

如何使核心数据绑定与子视图和多发钞银行发挥很好的任何想法?

Any ideas on how to make Core Data bindings play nicely with subviews and multiple NIBs?

推荐答案

您有两个树控制器。每个人都有自己选择的知识。尝试结合 selectionIndexPaths 无论从树上控制器到您的文档的属性(你需要提供一种方法,通过视图控制器到那里)。

You have two tree controllers. Each has its own knowledge of the selection. Try binding selectionIndexPaths from both of the tree controllers to a property of your document (you'll need to provide a way to get there through the view controller).

这篇关于与子视图和多发钞银行核心数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆