The first difference, is that I constructed my data source programmatically not in IB. There is no logistical difference between the one you created in IB and the one I created in code. I just prefer to do it this way.
The difference I pointed out with your example (and believe me, I certainly have considered the obvious language barrier) was in telling him to add a hidden column to the table view. A column is an interface element, not a data element. You add data columns to a data source to identify the possible columns in a data source. The purpose for this is to enable automatic key/value matching when assigning the data source to a table. If your table has two columns, i.e. “path” and “icon”, it automatically inserts data from your data source into the appropriate column. In your table’s data source, you add data rows, which in turn contain data cells. These cells associate themselves automatically to the appropriate columns by the same key/value mechanism. So, if you have data source with data rows, all of which have two cells named “path” and “icon”, the data from the respective data cells automatically lines itself up with the corresponding data columns in the data source. Data cells and columns are different things, as are the data source and the table itself. Just because I declare a ‘path’ column in the data source doesn’t mean that I have to have a matching table column in my table. Remember, a data source is just that… an object that stores data as a source for other objects to access. When I set the data source for the table, it goes through the columns for the table and looks for matching data columns in the data source. If it finds one, it uses the values for data cells matching the data column as the source for that column. If it doesn’t it might enter null values or throw an error. But, if there are extra data columns in the data source they are ignored by the table, because it only wants data that matches it’s configuration.
For example, say I have this data source…
data source “DataSourceX”
– data column “Name”
– data column “Age”
– data column “Height”
– data column “Weight”
Then I add some data rows to it, all of which provide the appropriate values in their corresponding data cell values. The beauty of data sources, is that I can now use this data source dynamically with any object compatible with the data source. In fact, I can use the same data source with multiple table views if I want.
I could have one table view that only shows name and height…
table view “TableView1”
– table column “Name”
– table column “Height”
I could have another that shows all available fields, just the name, etc. The only thing I need to do to is add table columns with corresponding names, and then set the data source as the data source for that table, and it will automatically make the appropriate associations. In my example app, my table only has an ‘icon’ column… there is NO path column. But, when you click on the table and get a reference to it’s selected data row, you then have access to all of the other data cells of the data row… including the ones that your table doesn’t implement… thus exploiting the POINT of having a data source.
The biggest difference between my code and yours, is that I gave him working code that uses the correct approach to achieving his goal. You told him to add another column to his table view. If he were to try to add just a column to the table or the data source, it wouldn’t allow him the get the path of the image. He needs to add rows to the data source that include the “hidden” ‘path’ cell, which he can access the value of to get the path. I’m not trying to make my comments personal, I’m just pointing out semantic differences that are important, that might save PaulB a lot of time and keep him from trying to go about things that wrong way. I also provided real, tested code that actually does what he wants. To be an effective contributor, you need to do more than post telling people that “It doesn’t work that way”. You have to tell, and often show, them how it does work. Adding a data column to a data source and it’s corresponding data cells is the right way to create a data source. Adding a table column to a table to hold a path that you don’t want to be visible IS a hack. Either get your facts straight or your wording. Again, nothing personal, your comments are just misleading to people who already don’t understand something.