I'm trying to discover the differences between dataSources and delegates.
DataDource is for functions dealing with populating the table
func tableView(UITableView, cellForRowAt: IndexPath) -> UITableViewCell
Asks the data source for a cell to insert in a particular location of the table view.
func numberOfSections(in: UITableView) -> Int
Asks the data source to return the number of sections in the table view.
func tableView(UITableView, numberOfRowsInSection: Int) -> Int
Tells the data source to return the number of rows in a given section of a table view.
func tableView(UITableView, titleForHeaderInSection: Int) -> String?
Asks the data source for the title of the header of the specified section of the table view.
func tableView(UITableView, titleForFooterInSection: Int) -> String?
Asks the data source for the title of the footer of the specified section of the table view.
Note that 2 of those func are required.
Delegate are for the behavior of the table, such as
func tableView(UITableView, willSelectRowAt: IndexPath) -> IndexPath?
Tells the delegate that a specified row is about to be selected.
func tableView(UITableView, didSelectRowAt: IndexPath)
Tells the delegate that the specified row is now selected.
func tableView(UITableView, willDeselectRowAt: IndexPath) -> IndexPath?
Tells the delegate that a specified row is about to be deselected.
func tableView(UITableView, didDeselectRowAt: IndexPath)
Tells the delegate that the specified row is now deselected.
Note that none is required, that's why you can (but should not) omit.
--------------------------------
can a tableView update without the aid of a delegate?
If you don't use any delegate func, you don't need. But it is a bit risky.
I noticed similar question with pickers: if I omitted the datasource reterence, things kept working.
I filed a DTS and got the following answer
Note: filed a DTS (695575082) and got the advice to file this bug report.:
" This is as a result of iOS moving away from informal to formal protocol definitions.
The runtime checks if you conform and implement those methods and they get called.
You should definitely set the picker view’s dataSource to your view controller.
If not, when these are called:
func numberOfComponents(in pickerView: UIPickerView) -> Int
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
… “pickerView” will be nil. Often times you want that to be valid value so to be sure you are targeting the right picker view (in the case of multiple picker views at once).
I consider this a bug in that you “should” set the dataSource. "
So, conclusion is : you SHOULD set a delegate and dataSource.
This can be done in IB, so it is really simple.