Observing NSArrayController's selection doesn't appear to be consistent
Observing NSArrayController's selection doesn't appear to be consistent
- Subject: Observing NSArrayController's selection doesn't appear to be consistent
- From: Chris Liscio <email@hidden>
- Date: Tue, 15 Feb 2005 18:40:40 -0500
Greetings,
I have toyed around with this issue for a few days, and now I'm here. I have changed over most of my code to use bindings in an attempt to better manage the flow of data around my application. Previously, I was using a whole bunch of NSNotifications, and the design was getting out of control. My controllers were getting huge, maintenance was a pain, and I was an unhappy camper.
(This is going to be a hella-long email, and I hope to be as concise as possible. This is a pretty sticky issue, and hopefully it'll help others who are experiencing this problem. I'm hoping to get the pros out of the woodwork, and hopefully they'll be able to help me get this going.)
The next version of FuzzMeasure consists of a document that contains multiple measurement records. For each measurement record, there is both a recorded impulse response (just a hunk of NSData) and a window (of type SMUGWindow). Using the window, combined with the impulse, I'm able to extract the frequency response from a particular measurement record.
I have a single NSDocument subclass (FuzzMeasureDocument), which overrides makeWindowControllers. I create a Measurement window, a Frequency window, and an Impulse window to "visualize" the document. The Measurement window lists all the records in the document, the impulse window allows the user to modify the currently selected record's impulse, and the Frequency window displays the frequency responses of the currently selected records (it supports multiple items selected in the table view).
The document maintains a NSMutableArray of measurement records, and it also has an NSArrayController which is accessible by the window controllers via [[self document] arrayController].
In the Measurement window's controller, I bind the table view's columns to the date and comment of the records stored in the document. That seems to work perfectly fine. No issues here.
In the Impulse window's controller, within windowDidLoad, I bind my impulse response view's "impulse" and "impulseWindow" bindings to [[self document] arrayController]'s "selection.impulse" and "selection.impulseWindow". This seems to work fine as well, and the view is smart about not displaying multiply selected curves. This works fine as well.
In the Frequency window's controller, within windowDidLoad, I actually bind my own impulse and impulseWindow bindings to [[self document] arrayController]'s "selection.impulse" and "selection.impulseWindow". Upon receiving observeValueForKeyPath calls, I perform the FFT on the impulse response, and display the curves in my plot view. I didn't want the plot view to have "smarts" about calculating FFTs and all that (because it has to just throw curves in a view, nothing more), and this is why I put the logic into the controller.
So, where am I whining about inconsistency? If I load my impulseWindow first, and my frequencyWindow second (which causes impulseWindow to bind its impulse view first, and frequencyWindow to bind itself second), frequencyWindow only gets observeValueForKeyPath calls when the selection has only one item. Once I select multiple items, only the impulseWindow's view gets the observeValueForKeyPath calls.
e.g.
2005-02-15 17:54:56.778 FuzzMeasure[575] impulseView -- observeValue <NSArrayController: 0x3e8ba0>[object class: NSMutableDictionary, number of selected objects: 1] (selection.impulseResponse)
2005-02-15 17:54:56.780 FuzzMeasure[575] impulseView -- observeValue <NSArrayController: 0x3e8ba0>[object class: NSMutableDictionary, number of selected objects: 1] (selection.impulseResponseWindow)
2005-02-15 17:54:56.780 FuzzMeasure[575] freqWindowController -- observeValue <NSArrayController: 0x3e8ba0>[object class: NSMutableDictionary, number of selected objects: 1] (selection.impulseResponse)
2005-02-15 17:54:56.786 FuzzMeasure[575] freqWindowController -- observeValue <NSArrayController: 0x3e8ba0>[object class: NSMutableDictionary, number of selected objects: 1] (selection.impulseResponseWindow)
2005-02-15 17:54:57.737 FuzzMeasure[575] impulseView -- observeValue <NSArrayController: 0x3e8ba0>[object class: NSMutableDictionary, number of selected objects: 2] (selection.impulseResponse)
2005-02-15 17:54:57.737 FuzzMeasure[575] impulseView -- observeValue <NSArrayController: 0x3e8ba0>[object class: NSMutableDictionary, number of selected objects: 2] (selection.impulseResponseWindow)
Now, if I load the Frequency window first, and then the Impulse window second, everything works perfectly. This is the inconsistency.
I have previously implemented the Frequency window controller as simply registering with the arrayController and asking to observe the "selection" keyPath, but that didn't work any differently.
It would seem as if there's something wrong with the way I'm binding, but there's no reason why binding in one order would cause bindings to break in the other order. I have exactly the same implementation for binding in my Frequency window controller as my Impulse view.
Any help with this issue would be greatly appreciated, and I'm sure that others who are getting further along into their work with bindings may also find this helpful.
Have a great day!
<x-tad-smaller>Chris Liscio
http://www.SuperMegaUltraGroovy.com
Finally! MLS Software for Mac OS X. http://www.FuzzMeasure.com
</x-tad-smaller>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden