简体   繁体   中英

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 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. I think you're running into run loop / timing problems with Bindings and using this method should mitigate that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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