This post is adapted from the example in the first section of the Apple Bindings docs, at the end of that section, which introduces Vlad, Attila and Co. and their weapons. (This is not about the real Vlad, whose descriptor was apparently well-deserved). We have a Table View that displays three combatants: Maximus (ancient), George (colonial), and Neo (modern). Each combatant has an appropriate choice of weaponry, displayed with a popup button. The code is pretty standard. There is a combatant class which keeps track of its name, possible weapons, and the current selected Weapon:
class Combatant(NSObject): |
In the AppDelegate's init method, we instantiate three Combatants (one from each era), and save them in a list called combatantL:
class PyFightAppDelegate(NSObject): |
The bindings are set up as shown in the tutorial:
1. Combatant controller => AppDelegate => => combatantL
2. Window title => Combatant controller => selection => name
3. Table Column => Combatant controller => arrangedObjects => name
4. Weapon controller => Combatant controller => selection => weaponL
5. Pop Up Button => Value => Weapon controller => arrangedObjects
6. Pop Up Button => Selected Object => Combatant controller => selection => selectedWeapon.