基于视图的 NSTableView 中的 NSButton 参数绑定
基于视图的 NSTableView,具有单列。每个“单元格”包含多个 NSTextField、一个 NSImageView 和一个 NSButton,所有这些都绑定到 Table Cell View 的 objectValue 的各种属性。 NSTableView的内容绑定到NSArrayController的arrangedObjects上,NSArrayController处于实体模式并绑定到相关的NSManagedObjectContext。
NSTextFields 和 NSImageView 的行为符合预期。然而,出于某种原因,NSButton 却没有。它始终处于禁用状态。我已将其参数绑定到 objectValue 的属性,并将其目标绑定到文件所有者。实验表明,是参数绑定而不是目标绑定造成了问题。印象是参数值必须为零,因此导致按钮被禁用。但它确实不可能,因为其他绑定(NSTextFields 等)工作正常。
我在基于单元格的表格视图中多次使用按钮参数/目标绑定,没有出现任何问题。所以我认为基于视图的表视图的某些特征可能意味着此类绑定不起作用。但 Apple 的 TableViewPlayground 示例使用这种方法(在 HUD 面板中)没有问题。我的绑定是以完全相同的方式设置的。我能看到的唯一区别是苹果的示例使用类模式数组控制器,而我的示例使用实体模式。但我不敢相信这就是问题所在(或者至少我非常希望这不是问题,因为这将是一个严重的弱点)。
View-based NSTableView with a single column. Each 'cell' contains several NSTextFields, an NSImageView and an NSButton, all of which are bound to various attributes of the objectValue of the Table Cell View. The NSTableView's content is bound to the arrangedObjects of an NSArrayController, which is in Entity mode and bound to the relevant NSManagedObjectContext.
The NSTextFields and NSImageView behave as expected. For some reason, however, the NSButton does not. It is always disabled. I have bound its argument to a property of the objectValue and its target to the File's Owner. Experimentation indicates that it is the argument binding rather than the target binding that is causing the trouble. The impression is that the argument value must be nil, so causing the button to be disabled. And yet it really cannot be, because the other bindings (NSTextFields, etc) work fine.
I have used button argument/target bindings many times in cell-based table views without problems. So I thought perhaps there was some characteristic of view-based table views that meant such bindings do not work. But Apple's TableViewPlayground sample uses this approach (in the HUD panel) without issue. My bindings are set up in exactly the same way. The only difference I can see is that Apple's example uses a class-mode array controller whereas mine is entity-mode. But I can't believe that that is the problem (or at least I very much hope it isn't as that would be a severe weakness).,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我花了几个小时来解决这个完全相同的问题。就我而言, NSTableView 的委托也没有设置为文件的所有者。一旦设置完毕,一切就开始正常运行。
I spent a few hours on this exact same problem. In my case, the NSTableView's delegate was not set to the File's Owner as well. Once setting that, everything started to function properly.