在NSSplitViewController内部的两个视图控制器之间传递数据的正确方法是什么? [英] What is the proper way to pass data between two view controllers inside a NSSplitViewController?
问题描述
概述:我的应用程序结构如下:
Overview: My app structure looks like this:
NSSplitViewController
`- SidebarViewController
| `- NSOutlineViewController
| `- NSTreeController
| `- SidebarEntity (static)
`- ContentViewController
`- NSTableViewController
`- NSArrayController
`- ContentEntity (CoreData)
任务:我想根据侧边栏中的选择过滤 ContentEntity
列表。
Task: I would like to filter ContentEntity
list based on selection in the sidebar.
问题:我不知道从 SidebarVC
到 ContentVC
。
环境:XCode 8.2.1,Swift 3,OS X 10.11.6
Environment: XCode 8.2.1, Swift 3, OS X 10.11.6
推荐答案
在浏览了与可可有关的书籍之后,我发现了被认为是正确的解决方案。我创建了一个 SidebarVCDelegate
协议,该协议具有接收侧边栏选择更改的正确方法,在 ContentVC
内进行了正确的过滤,然后边栏的 NSSplitController
委托,根据委托的调用过滤结果集。
After browsing through Cocoa related books I've found the solution that is considered the "proper" one. I sould create a SidebarVCDelegate
protocol with proper method for receiving sidebar selection change, make proper filtering method inside ContentVC
, and make the NSSplitController
a delegate for the Sidebar, filtering the result set based upon the call from delegate.
这篇关于在NSSplitViewController内部的两个视图控制器之间传递数据的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!