Question about chapter

Hi all, I’m running into some difficulty understanding Ch11. I’m hoping someone can help.

  1. In what appears to be page 246 of my ebook, there is a paragraph that says:

“Now you will implement tableView(_:commit:forRow:), a method from the UITableViewDataSource protocol. (This method is called on the ItemsViewController. ”

What does “this method is ‘called on’ the ItemsViewController” mean? Who calls it? When does it get called? Where is this documented? I don’t understand what this is saying, and what it means. ItemsViewController is the table view’s dataSource? Is this set somewhere, or is this implied?

  1. A little earlier on this page it says:

“Before the table view will delete a row, it calls a method on its data source about the proposed deletion and waits for confirmation.”

I don’t understand what it means that the tableView called a method on its dataSource and waits for confirmation. Is this something that is triggered by the code that I entered, or is this something that the class just knows how to do? Where is this confirmation documented? Is there another way to do the confirmation? Where in the code does the confirmation actually take place?

I think I am getting confused when the writers personify the objects, but are not clear about which actions we are triggering in code, versus which ones the classes automatically handle. A drawing would be helpful.

I already plan on reading Ch10 and 11 again, but thought I would post this question since someone else might have it as well.

When a delete button is pressed, tableView(_:commit:forRow:) is triggered (or is called) & the code written inside this method is executed.

Don’t worry even if you don’t understand everything. Just keep coding the examples in the book. They will make sense later when you finish the complete app.

Thanks, Sachin, I appreciate the help and support. I’ll understand it soon I hope!

What does “this method is ‘called on’ the ItemsViewController” mean? Who calls it? When does it get called? Where is this documented? I don’t understand what this is saying, and what it means. ItemsViewController is the table view’s dataSource? Is this set somewhere, or is this implied?

It means that ItemsViewController is the tableview datasource. So, when user tap on delete button on a tableview’s row, tableview call that method on its datasource (ItemsViewController is a subclass of TableViewController and this implies that the datasource and delegate property of tableview is already hooked up for you to its viewcontroller). More on Apple Documentation.

“Before the table view will delete a row, it calls a method on its data source about the proposed deletion and waits for confirmation.”
I don’t understand what it means that the tableView called a method on its dataSource and waits for confirmation. Is this something that is triggered by the code that I entered, or is this something that the class just knows how to do? Where is this confirmation documented? Is there another way to do the confirmation? Where in the code does the confirmation actually take place?

tableview call that method on its datasource (more details in my previous answer). That method, if implemented (if you actually override it) happens to return a boolean. That boolean is taken in account to procede or abort the action started by user. Thus, your code inside that method will determine confirmation or not.

I think you might as well reread some previous chapters in order to fully understand things that in further chapters are taken for granted like datasource/delegate patterns.

Once again, Apple Documentation is exhaustive. Eventually, you’ll master it and all the useful info within.

Hi,
I think what you should do is to read again the chapter which explains on Model-View-Controller pattern.

Before this chapter, we already set our ItemViewController as DataSource And Delegate for TableView. If you go to Main.storyboard and Ctrl+Click on ItemsViewController you will see that connection.