I donβt know if what I see with the pop-up button populated with bindings with a value transformer is what it should be or not, an unusual thing that I see (at least as regards visible with the values ββof transformers and table views) lies in the fact that the value parameter in the convertedValue: method is the entire array bound to the controller of the array, not individual rows in the array. When I did this with table views, the transformer is called once for each displayed row in the table, and the value parameter is any object attached to this row and column, and not the entire array that serves as the content array for the array controller .
I have a very simple application to verify this. The application delegate has the following:
+(void)initialize { RDTransformer *transformer = [[RDTransformer alloc] init]; [NSValueTransformer setValueTransformer:transformer forName:@"testTransformer"]; } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.theData = @[@{@"name":@"William", @"age":@"24"},@{@"name":@"Thomas", @"age":@"23"},@{@"name":@"Alexander", @"age":@"64"},@{@"name":@"James", @"age":@"47"}]; }
In the RDTransformer class, this is:
+ (Class)transformedValueClass { return [NSString class]; } +(BOOL)allowsReverseTransformation { return NO; } -(id)transformedValue:(id)value { NSLog(@"%@",value); return value; }
In IB, I added NSPopupButton to the window and the array controller to the list of objects. The controller content array is bound to the App Delegate.theData and the popup button content values ββare bound to the Array Controller.arrangedObjects.name with the transformer of the testTransformer value.
When I run the program, the log from the transformValue: method is:
2012-09-19 20:31:39.975 PopupBindingWithTransformer[793:303] ( ) 2012-09-19 20:31:40.019 PopupBindingWithTransformer[793:303] ( William, Thomas, Alexander, James )
This is not like other people's experience that I see on SO. Is there something I am doing wrong with bindings or a value transformer?