Re: Bound NSPopUpButton + null at the beginning
Re: Bound NSPopUpButton + null at the beginning
- Subject: Re: Bound NSPopUpButton + null at the beginning
- From: Stamenkovic Florijan <email@hidden>
- Date: Wed, 27 May 2009 15:59:49 -0400
On May 26, 2009, at 16:55, Stamenkovic Florijan wrote:
Hi all,
I am trying to figure out how to properly accomplish the following,
and after reading docs, references and googling, I am still stuck.
Any help appreciated:
1. Have an NSPopUp, "Contents" and "Content values" bound to an
NSArrayController's "arrangedObjects" and "arrangedObjects.name",
respectively.
2. Have the window title bound to the NSArrayController
"selection.name", and have a replacement string in case of no(null)
selection, or empty selection
3. Have a selectable null at the beginning of the popup.
I have two possible solutions, but both are flawed.
1. Bind the NSPopUp's selected index to NSArrayController's selected
index. Use "Inserts Null Placeholder" in the Contents binding to
make sure I get a selectable null at the beginning of the popup. The
problem is that if I at some point choose the null in the popup, the
window title does not get updated with the replacement string, and I
get a log statement:
[<NSArrayController 0x1340f0> setNilValueForKey]: could not set nil
as the value for the key selectionIndex.
2. To work around this, I tried adding an [NSNull null] at the
beginning of the NSArrayController's contents array. And deselect
the "Inserts Null Placeholder" in popup's contents binding. This
solves the selectionIndex issue, but it introduces a different
problem. Now if I select the null in the popup, my window title does
not get updated with the replacement string, but with the "<null>"
text. It seems that [NSNull null] is not seen as something to be
replaced with the Null replacement string. I also get a log statement:
Cannot create NSArray from object <null> of class NSNull
Is there an elegant way of dealing with this? I am thinking that
somehow it should be possible to bind the popup selected value
directly to the controller's selection. Then I could use the
approach described under (1), but avoid the index issue. However, I
can't seem to do that. The "Selected object" binding of the popup
seems to be incompatible with the NSArrayController "selection", as
the NSArrayController seems to wrap the selection in a proxy. The
NSArrayController's "selectedObjects" deals with NSArrays, not
individual values. Perhaps if I used a custom value converter that
converts from NSArray* to it's object at 0 index? Or is there a
better solution?
The value converter approach seems to work OK, in case anyone is
interested. I'd still be happy to learn a more concise way to do this,
if there is one.
F
_______________________________________________
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