Is there a consensus on the easiest method of getting data into a table view? I remember seeing a post about using bindings but I couldn’t seem to find it to research it.
I’m currently using tableView_objectValueForTableColumn_row_ and numberOfRowsInTableView_
While I’m at it, is a source list handled similarly or entirely different?
if you need just to display an array of data and do an action after selecting a row, the tableview datasource delegate (your mentioned methods) is the easiest way.
If you need more complex stuff like editing, special cell appearance, custom classes, or even Core Data, NSArrayController is the better choice.
I think this is a matter of opinion and what you’re used to doing. I always do it with bindings, and find that method to be the easiest. Maybe it’s because that’s the way I learned first.
How does this method work? I’ve been curious about it.
You’re right. But I learned and I’m using both methods depending on the purpose
No, I think bindings are generally easier (and better). Less code is generally better, and bindings provides things like automatic sorting, which can be a pain in AppleScript. Because it’s effectively running code in Objective-C rather than AppleScript, it can also be snappier for some things – this can be very noticeable with large amounts of data.
Of course, sometimes you can’t use bindings.
OTOH, I think the issue is a bit less clear-cut if you are writing in Objective-C.
Do you mean, how do you set up the bindings for a table view, or how do bindings work their magic behind the scenes?
Yes, how to you set up the table view to use bindings?
It’s very simple. You create an array to hold the data and assign that to a property. You add an array controller in IB, and bind its content Array to the class your array was created in with a model key path of the name of the array (so if your array is called theData and is in the app delegate, then you choose App Delegate from the pull down menu, select the “Bind to” check box and type theData into the Model Key Path field). The columns in your table are then bound to the array controller with a Controller Key of arrangedObjects with the Model Key Path being one of the keys in your array of dictionaries (assuming you have a multi-column table – if it’s a single column table, then the array would be a simple array and there would be nothing in the Model Key Path field).