0
votes

I need to create/use a NSTableView programmatically. From the documentation, it seems that I would implement the NSTableViewDataSource protocol. But the function tableView:objectValueForTableColumn:row: suggest (because of the row index) that I would have to manually take care of the sorting. Is that right? Also, as this is called on every redisplay, that might be slow because I am using Python and it would mean a Python call for every row/column.

I wonder wether it make sense to use Cocoa binding and wether that would be more simple. In any case, I would have to do that programmatically and I am a bit stumbled about how to that. From other examples, I guess I would create a NSArrayController and bind it all together somehow.

Also, I want to have it working on older MacOSX, so I guess I have to use the cell-based NSTableView, whatever that means.

The data source will be static and is not editable, i.e. I can just provide a NSArray with the data.

2

2 Answers

0
votes

There are three ways to use NSTableViews: 1) delegate methods; 2) NSArrayController; or 3) Bindings. My best advice to you is to learn all three of these in Xcode on a Cocoa ObjC project first before attempting to do this in python. Note: I'd also recommend that you first learn how to do these via nibs and then figure out how to do it programmatically (again in Xcode on a Cococa ObjC project before attempting it in python).

If you understand how Interface Builder (view in Xcode 4, app pre-Xcode4) bindings work then for the following code "Bind To" corresponds to myController, "Controller Key" would be "selection", and the Model Key Path would be "fullPath".

[myView bind: @"valuePath" toObject: myController withKeyPath: @"selection.fullPath" options: nil];

0
votes

You just need to sort your array once, then when the delegate method is called access the appropriate index in the array.

You really should have a good read of the Table View Programming Guide.