I have an NSPopupButton whose content is bound to an NSArray, let’s say the array is
@[
@"Option 1",
@"Option 2"
];
Its selected object is bound to User Defaults Controller, and is written to a preference file by the user defaults system.
In my code I check whether the preference is set to @"Option 1"
or not, and perform actions accordingly.
This all worked well (though I did feel a little uneasy checking for what is essentially a UI value, but whatever...) until I needed to localize.
Because the value is the label, I’m having an issue.
If my user is in France, his preferences file will say @"L’option 1"
, which is not equal to @"Option 1"
. I need to abstract the presentation from the meaning and it's proving pretty difficult.
I split up the binding into two arrays, let's call them values
and labels
.
Let’s say they look like this:
values = @[
@"option_1",
@"option_2"
];
labels = @[
NSLocalizedString(@"Option 1", nil),
NSLocalizedString(@"Option 2", nil)
];
I’ve bound the NSPopUpButton
’s Content
binding to values
and its Content Values
binding to labels
. However, the popup list is showing option_1
and option_2
, it does not seem to want to use the labels
array to label the items in the popup button.
How do I get the NSPopUpButton
to use values
internally and store that in the preferences file, but display labels
to the user?
It doesn’t have to be architected this way, if you can think of a better solution. The point is I want to store and check one value, and have that value associated with a label that gets localized appropriately.