简体   繁体   English

NSTableColumn值绑定到最前端窗口的NSArrayController在窗口更改时引发异常

[英]NSTableColumn value-bound to frontmost window's NSArrayController throwing exceptions on window change

I have an NSTableView in a floating window that gets dynamically bound to the arrangedObjects property of an instance of an NSArrayController that corresponds to the frontmost document window with code like the following: 我有一个NSTableView在被动态绑定到一个浮动窗口arrangedObjects对应于最前面的文档窗口,如下面的代码一个NSArrayController的实例属性:

NSArrayController *documentSpecificArrayController;  // properly set elsewhere
NSTableColumn *tableColumnToBind;  // properly set elsewhere

[tableColumnToBind unbind:NSValueBinding];
[tableColumnToBind bind:NSValueBinding
               toObject:documentSpecificArrayController
            withKeyPath:@"arrangedObjects"
                options:[NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES],
                         NSContinuouslyUpdatesValueBindingOption,
                         nil]];

As long as the represented array/the table view are empty, things work fine; 只要所表示的数组/表视图为空,就可以正常工作; all of the various operations on the table view/represented array within one document work fine. 一个文档中的表视图/表示的数组上的所有各种操作都可以正常工作。 If one switches from a document with a non-empty represented array to a document for which the represented array is empty, an endless stream of *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0) exceptions are thrown. 如果从具有非空表示数组的文档切换到表示数组为空的文档,则会抛出*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)异常流。 。

Am I missing something that I need to do in cleanly severing the binding when switching windows? 在切换窗口时,我是否缺少在彻底断开绑定时需要做的事情? Something else? 还有吗 (Is there some specific information that I've omitted that would help diagnose my error?) (是否省略了一些有助于诊断错误的特定信息?)

Based on your comment it seems you might be trying to create an inspector palette or something similar. 根据您的评论,您似乎可能正在尝试创建检查器调色板或类似的东西。 Is this true? 这是真的? If so, you should probably just bind directly to the active document's array controller by binding to Shared Application with the key path of mainWindow.document.myArrayController. 如果是这样,您可能应该通过使用mainWindow.document.myArrayController的关键路径绑定到Shared Application来直接绑定到活动文档的数组控制器。 I think you're running into run loop / timing problems with Bindings and using this method should mitigate that. 我认为您正在遇到绑定的运行循环/计时问题,使用此方法应该可以缓解这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM