核心数据绑定与子视图和多个NIB [英] Core Data bindings with subviews and multiple NIBs

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

问题描述

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



我使用的技术视图切换具有多个视图控制器),如在Hillegass书中所解释的。我的所有子视图由ManagedViewController控制,我的子类NSViewController有一个managedObjectContext字段。



我的子视图存在于一个单独的nib文件中。由于某些原因,我在该nib中设置的绑定不工作 - 但是如果我在主nib文件中以完全相同的方式设置窗口小部件和绑定,它们可以正常工作。



查看图片:





在第二个nib文件中,我有另一个树控制器,其managedObjectContext绑定到文件的所有者的mOC(文件的所有者是我的ManagedViewController)。 NSTextField的值的绑定方式与上述方式相同。



在我的代码中,我已经测试过,以确保两个managedObjectContexts引用同一个对象。



我没有得到一个错误 - 这只是值从不绑定到NSTextViews在子视图。



此外,我尝试过NSTextFields - 同样的问题。



解决方案

你有两个树控制器。每个人都有自己的选择知识。尝试将两个树控制器中的 selectionIndexPaths 绑定到文档的属性(您需要提供一种通过视图控制器访问的方法)。


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.

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.

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.

See image:

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.

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.

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.

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

Also, I have tried NSTextFields--same problem.

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

解决方案

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).

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

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