通过 NSArrayController 绑定 NSOutlineView
我有一个应用程序,可以播放具有如下结构的歌曲(曲目)([] 括号代表“列表”):
SidebarController (NSObject)
SidebarContentController (NSArrayController)
[
ListController (NSArrayController)
[
TrackModel (NSObject)
]
]
我正在 InterfaceBuilder 中使用绑定。只要我有这个结构,一切都很好,我可以将 NSTableView 的内容绑定到 SidebarController: self.sidebarContentController.selection.arrangedObjects
现在我想使用 NSOutlineView 因为我想要显示用户能够打开和播放的播放列表。所以结构现在看起来像这样:
SidebarController (NSObject)
SidebarContentController (NSArrayController)
[
ListController (NSTreeController)
[
PlaylistModel (NSObject)
[
TrackModel (NSObject)
]
]
]
但现在我无法绑定 NSOutlineView self.sidebarContentController.selection.arrangedObjects 因为当我启动应用程序时出现异常:
*** -[NSProxy doesNotRecognizeSelector:_mutatingNodes] called!
当我尝试像这样的简单结构时它效果很好:
ListController (NSTreeController)
[
PlaylistModel (NSObject)
[
TrackModel (NSObject)
]
]
然后我可以将它与 self.arrangedObjects 绑定ListController 和 NSOutlineView 上的 code> 显示所有播放列表和曲目。但我确实需要 SidebarContentController,因为我不仅有一个播放列表列表,而且有多个。
任何想法出了什么问题吗?这是应用程序的屏幕截图,以便您了解为什么我需要 SidebarContentController:
我需要 NSTableView 成为NSOutlineView 能够显示树形结构。
I have a application which plays songs (tracks) with a structure like this (the [] brackets represend 'a list of'):
SidebarController (NSObject)
SidebarContentController (NSArrayController)
[
ListController (NSArrayController)
[
TrackModel (NSObject)
]
]
I am using bindings in the InterfaceBuilder. As long as I had this structure everything was fine and I was able to bind the contents of a NSTableView to the SidebarController with: self.sidebarContentController.selection.arrangedObjects
Now I wanted to use a NSOutlineView instead because I wanted to show Playlists which the user will be able to open and play. So the structure looks like this now:
SidebarController (NSObject)
SidebarContentController (NSArrayController)
[
ListController (NSTreeController)
[
PlaylistModel (NSObject)
[
TrackModel (NSObject)
]
]
]
But now I can not bind the NSOutlineView withself.sidebarContentController.selection.arrangedObjects
because when I start the application I get an exception:
*** -[NSProxy doesNotRecognizeSelector:_mutatingNodes] called!
It works well when I try a simple structure like:
ListController (NSTreeController)
[
PlaylistModel (NSObject)
[
TrackModel (NSObject)
]
]
then I can bind it with self.arrangedObjects
on the ListController and the NSOutlineView shows all the playlists and the tracks. But I really need the SidebarContentController because I have not only one list of playlists but several.
Any Ideas what is going wrong? Here is a screenshot of the application so you understand why I need the SidebarContentController:
I need the NSTableView to become a NSOutlineView to be able to show a tree structure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信你的问题的根源是在你的模型中使用控制器。正如结构图中所表达的,假设“列表”相当于一个数组,你有:
相反,你应该有:
绑定每个视图的控制器对象(两个表视图和一个自定义视图;因此两个 NSArrayController,也许还有一个 NSObjectController)到模型中的适当内容(第二个 NSArrayController 的内容取决于第一个的选择)。
此时,您可以想象在模型中添加另一个层(播放列表的列表?),用 NSOutlineView 替换第二个 NSTableView,并用 NSTreeController 替换第二个 NSArrayController。
I believe the source of your problem is the use of controllers in what is essentially your model. As expressed in your structure diagrams, and assuming "list of" equates to an array, you have:
where instead you should have:
with controller objects that bind each view (two tableviews and a custom view; thus two NSArrayController's and perhaps an NSObjectController) to the appropriate content in your model (the second NSArrayController's content depending on the selection of the first).
At that point, you can visualize adding another layer to your model (List's of Playlist's?), substituting an NSOutlineView for the second NSTableView, and replacing the second NSArrayController with an NSTreeController.