Rows vs. Cells: Image in tutorial backwards?

I may be showing my ignorance but in Checklists v5.0 on page 21 it would seem that the words in the image are backwards. The data source (View Controller) should be handing rows to TableView, not cells. So shouldn’t the dialog be “Can I have the row for the first cell” followed by “OK here is the first row”, then “Can I have the row for the second cell” followed by “OK, here is the second row”.
Or am I confused?



The TableView asks for all the rows first. From what I understand, this is so it knows how much memory to allocate for all necessary rows. Then it will proceed to ask for the cell associated with each row.

The contents of a row is a cell, but the row is repeated for as many cells as you need. So, it is more efficient to get the data for all the rows then fill the data of the cells that are being shown.

At least, that is how I understand it.

Possibly you’re just not familiar with the terminology Apple uses. In iOS, the cell is the visual component which appears on the screen. The row is the coordinate. The table view asks its delegate for the cell it should display on each row.

You are right, it is a terminology question. View Controller is the data source, so it knows about rows of data. Table View wants to populate its cells (things that it is displaying) with (typically) a subset of those rows of data. So (in my view) Table View should be asking “What row goes into Cell 1?” rather than “what cell goes into this row?”. Does that make my confusion clearer?

@achibition The cell has the data. The row just is the location (how it keeps the correct order) of the cells. The TableView is asking, “What cell goes here in this row and what data is in that cell”

Maybe a discrete example will help me. Let’s say I have 20 rows of data and ten visible cells on the phone screen to display those data. Somebody needs to know that we are currently displaying rows 7-16 in cells 1-10. Who is keeping track of that translation? If View Controller is, then VC is saying “I’ve just populated cells 1-10 with the correct data. You ask for a cell, I’ll give you a cell”. Alternatively TableView could be doing the translation, saying “I’m keeping track, so give me row 7 and I’ll put it into cell 1, etc”. Who is in charge???

There are two roles here. One is the table view. The other is its data source. (The view controller is the data source in this case). The data source manages the data. The table view manages displaying that data. We separate the responsibilities. Table views can display lots of different kinds of data, so we give it a consistent behaviour and we let the data source do all the customising.

The table view knows that it will display data in a number of sections, that each section has a number of rows, and that each row will be represented by a cell. It asks the data source how many sections, how many rows in each section, and for a cell to use to display the row. It only retains enough cells to fill the space on screen, and it doesn’t care what’s in the cells - it asks the data source to manage that for it.

If the user scrolls up and row 17 becomes visible, it asks the data source for a cell to display the data for row 17. If row 7 disappears off the top, it enqueues that cell for later use. If row 18 becomes visible, it dequeues the cell which displayed row 7, and reuses it to display row 18. The data source keeps the data for all 20 rows, but the table view only needs 10 cells to display what the user can see at any given time, so only 10 cells are ever created.

1 Like

@narrativium, Thanks, that starts to make sense. I appreciate your time in responding.