Thursday, October 1, 2009

First bindings for the table view

The first post in this series is here.

I forgot something important there. We need to have the variable dataArray declared and implemented, and I didn't do that yet. Rather than just put it in the App Delegate, we'll define a new class to deal with the data and be bound to GUI elements. It is easier if we get Interface Builder to write the class file skeleton for us, so let's go to IB first, and then come back in the third post to talk about properties and the variable we need.

Now, it's time to set up the first binding. Open MainMenu.xib in Interface Builder. Pull out an Object and an Array Controller from the palette in the Library.

Click on the Object icon on the window labeled "MainMenu.xib - English" (or whatever), then bring up the Inspector window and choose the identity tab. Set the Class to "DataModel". The label on the icon will change automatically. From the Edit menu choose the menu item Write Class Files… (with the DataModel object still selected) and click through (click the checkbox for the .h file).

To set up the bindings, start with the table view. Click on the window, then click three times on column two of the table view (you should see labels for NSScrollView, NSTableView, and NSTableColumn in succession in the Inspector).

I notice that I also changed the title of the table column (it's visible in the screenshot), but that is not necessary for what we're doing. With the table column selected set its Value binding like this::

Click on the Array Controller in MainMenu.xib and set its Controller Content binding:

You can't run the application yet. But after part 3 you would be able to, and you should will see this:

I promise.

No comments: