开发者

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:

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.

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 wo开发者_如何学Pythonuld 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. I think you're running into run loop / timing problems with Bindings and using this method should mitigate that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜