For context, this question is from page 20 - 23 of the second tutorial (checklists)
When declaring the tableView(:numberOfRowsInSection:) and tableView(:cellForRowAt) what exactly are we doing ??
Below are my questions for someone who is hot on theory
Does declaring a method with the terms ‘override func’ mean that the specified view (tableView in this case) will call it ? This is as opposed to a method declared with just ‘func’ which we call ourselves within the code ?
The second parameters in each method, i.e. numberOfRowsInSection and cellForRowAt, do they always call and return the same values ? i.e. section and return Int for numberOfRowsInSection and IndexPath and UITableViewCell for cellForRowAt ?
With regards to practicality, is it just usefull to use these methods everytime we create a table like app ? Im wondering if getting too theoretical is not the best way to approach the subject and maybe just ploughing on until it all makes sense is a better approach.
Swift and the Cocoa frameworks do things in a bit of a weird way (especially if you’re coming from another language) but it does make sense.
You have to use
override func because UITableViewController already has its own version of these methods, and you are replacing that version with your own. In this case, yes, the UITableView will be calling those methods (note: there is a difference between UITableView and UITableViewController). However, this is not because they are marked with
I’m not 100% sure what you are asking, but
tableView(numberOfRowsInSection) always takes an Int for the section number and returns an Int for the number of rows.
tableView(cellForRowAt) always takes an IndexPath and returns a UITableViewCell object (or a subclass). Those labels,
cellForRowAt are part of the method name,
Yes, you use these methods every time you make an app with a table view.
I hope this helps!
For question 2 that is exactly what I was asking.