Re: NSComboBox, binding, multiple selection, multiple values == trouble
Re: NSComboBox, binding, multiple selection, multiple values == trouble
- Subject: Re: NSComboBox, binding, multiple selection, multiple values == trouble
- From: Keary Suska <email@hidden>
- Date: Wed, 23 Jan 2013 14:25:01 -0700
On Jan 23, 2013, at 10:28 AM, Markus Spoettl wrote:
> in my app, I can edit a selection of model objects in a window which that consists of NSTextFields and NSComboBoxes to edit model properties, all via binding to an NSArrayController's selection proxy.
>
> When I'm editing a multi-selection that has property values are different for individual model objects in the selection, I get an undesired behavior from NSComboBox:
>
> When I tab over an NSComboBox which displays the multiple-values placeholder, upon exiting the combo box, the corresponding property for all selected objects is nil'd. (BAD)
>
> When I do the same (tabbing over) with an NSTextField, the values of the individual objects' properties are unchanged. (GOOD).
I had a similar issue and I don't think it has anything to do with the binding. It seems to be that NSCombobox always sets the value as displayed when the field is exited regardless of whether the contents have been edited or not. So, if the contents are nil, it will set the value(s) to nil on exit. This may be an acceptable outcome when editing a single value, so it is probably overlooked. In my case it was unnecessarily dirtying the document edited state. My solution was to scrap comboboxes and instead use regular NSTextFields with autocompletion support provided by a formatter. It proved to be actually better in my situation--more intuitive to the user. Of course, these were fields whose possible contents are already known by the user, such as a name prefix (Mr Ms etc)
> Since I have no control over how NSComboBox implements its bindings and I therefore can't fix the handling of multi-valued selections, I fixed this by subclassing NSComboBox and implementing -objectValue by returning the NSMultipleValuesMarker object as I see fit.
>
> - (id)objectValue
> {
> id result = [super objectValue];
> if (returnMultiValuesMarkerForEmptyObjectValue) {
> if ([result isEqualTo:@""]) {
> result = NSMultipleValuesMarker;
> }
> }
> return result;
> }
>
> The private returnMultiValuesMarkerForEmptyObjectValue ivar is set to YES externally by my editor controller which knows that a multiple selection is being edited.
>
> This works reasonably well but I wonder how others have fixed this problem. I feel returning NSMultipleValuesMarker is a hack which works only because NSComboBox thinks it's a legitimate return value (or doesn't care). The fact that I can't clear properties for multiple selections is a side effect I can live with.
This actually works? I wouldn't think so--I would expect that all of the field values get set to the string value of NSMultipleValuesMarker, which is really what the code looks like it should be doing. If there are indeed some internals that are ignoring the marker, they are undocumented (AFAIK) and shouldn't be relied upon.
> Any better fixes for this?
If you are really dedicated to using NSCombobox, I would avoid bindings and instead handle it manually, using target-action. This way, when your controller receives the action you can check for a multiple selection and ignore it if so.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
- Prev by Date:
Re: NSComboBox, binding, multiple selection, multiple values == trouble
- Next by Date:
Re: NSComboBox, binding, multiple selection, multiple values == trouble
- Previous by thread:
Re: NSComboBox, binding, multiple selection, multiple values == trouble
- Next by thread:
Re: NSComboBox, binding, multiple selection, multiple values == trouble
- Index(es):