Hello,
Just another boring discovery.
Imagine you want to bind a pop menu to an array of objects (these objects may be dictionaries, Core Data entities or any other class). You bind the array of objects to the menu Content, via a controller (theController.arrangedObjects). This fills your menu with an object reference for each menu item. Then you want something more readable for the displayed items, so you bind the Content Values to some property / key of your objects (for example a name string): theController.arrangedObjects.name.
I had the idea to set my pop menu’s Content Values to the object itself (theController.arrangedObjects, with no key path) and add a NSValueTransformer, which takes the object as entry value and returns a string, based on the objects properties, for example stringWithFormat . After all, this works perfectly for a table view.
No way.
The NSValueTransformer is simply NOT called, and the items show the object default description (not really readable).
Sad. This means you have the following possibilities:
- Build a new array of, say, dictionaries, before the menu is displayed and bind this array to the Content Values to a dictionary’s key
- Put a new (non atomic) property into your object and bind this property to the Content Values
- Subclass the object and override its description method.
Subclassing just to implement this little functionality is painful, and if you subclass a Core Data entity, you have to be very careful (Apple tells there should be no reason to do so, because entities provide all the desired functionalities, and it sounds like a warning: “don’t do this or you’ll run into problems”).
I just can’t understand why the value transformer get called for table views and not for pop menus. Do you?
Regards,