On the left is the window of my app when it starts up, and on the right is the window after I've clicked the button a few times.
We have a button labeled "go" and an NSTableView (without scrollbars and not editable). The NSTableView is connected in IB as an outlet of the AppDelegate called tv. The button is connected to an action of the same name in the AppDelegate.
In order to serve as a data source for the table view, the AppDelegate implements the methods shown at the end of the listing. The data comes from an NSMutableArray called ds. We set up the data source in applicationDidFinishLaunching_() by calling addObjectsFromArray_() and feeding it a Python list of NSNumber objects. In the same function, we tell the tv that we are the data source.
The action happens in the go_() method. We pick a random NSNumber object from the data source, double its value, and replace that object in the data source. At the end, we tell the tv to reloadData. All manual, but it works. Here is the code:
|
Because of the way the bridge works, we could also do without the Cocoa objects and use a simple list of ints.