0

我正在构建一个基于 Core Data 的类似 iTunes 的应用程序,该应用程序NSTableView在主窗口中有一个,允许用户在表格视图中选择项目并执行“获取信息”,就像在 iTunes 中一样。目前,我正在处理单项获取信息窗口,当用户在主窗口(位于 中MainMenu.xib)中选择单个项目并按下 Cmd-I 时会显示该窗口。这会打开单项获取信息窗口(在 中SingleItemGetInfo.xib)。

主窗口中的表格视图通过绑定到NSArrayController. 如果我将一个NSArrayController放入SingleItemGetInfo.xib文件中,我知道这将是一个不同的NSArrayController.

那么,将单个项目获取信息窗口中的字段绑定到用户在主窗口的表格视图中所做的选择的正确方法是什么?

MainMenu.xib's Array Controller bindings:
Managed Object Context: AppDelegate.self.managedObjectContext

MainMenu.xib's Table View bindings:
Content: Array Controller.arrangedObjects
Selection Indexes: Array Controller.selectionIndexes
Sort Descriptors: Array Controller.sortDescriptors
4

1 回答 1

1

This will work mostly the same way it does when the master and detail views are in the same window. The primary difference is that you need to bind the selection of the array controller in the detail xib to the selection of the master array controller.

It depends on how you have your app organized as to how you accomplish this. If both views are run by the same object then you can just make the master array controller an outlet connected to the controller (@property IBOutlet NSArrayController *masterArrayController;). Then in the detail xib you can bind the selection of the detail array controller to the selection of the master array controller.

If each view has its own controller you might also consider just passing the managed object from the master view to the detail view. Then you can bind to each of the attributes of the managed object in your xib file (i.e. bind to File's Owner self.detailObject.fullName). If you pass a reference I think all of the changes will go right back into the managed object context.

于 2013-10-07T18:52:23.103 回答