This is a straightforward extension of other bindings we did recently. Click on the checkbox, if it becomes "ON" you get the chimp, if it's "OFF" you get President Bush.
The underlying data that supports the table view is an array of dictionaries (for KVC compliance), each with the key "isOn" and a boolean value. For convenience, the data is stored in a plist file and loaded into the project, as shown here.
There is a checkbox cell in the first table column's data cell, and an image cell in the second column's cell. Editing has been disabled for the second column. (We don't know how to turn an image into a boolean!)
The images are png files, added to the project as usual. They can be loaded in two different ways, as shown in the code. You could set it up variously, but I load the images in the App Delegate and then the value transformer asks for them, so getter methods are implemented in the App Delegate (not shown).
It all works great. There is only one problem: the images in the table view are washed out. Compare the originals:
I don't know why this is.
The bindings are straightforward. There is an array controller in the nib. It is connected like:
The first table column has this binding:
And the second table column has this binding:
Here is the code for the init method of the App Delegate where the data is loaded:
And this is the implementation of the Value Transformer: