Difference between UITableViewDelegate and UITable

2019-01-14 04:27发布

Anyone tell me the difference between UITableViewDelegate and UITableViewDatasource?

4条回答
可以哭但决不认输i
2楼-- · 2019-01-14 05:01

Complementing the answers, this is a sheet of all methods in delegate and datasource.enter image description here

see the original answer: delegate and datasource methods for UITableView

查看更多
爷、活的狠高调
3楼-- · 2019-01-14 05:01

UITableViewDelegate is a protocol you implement on your class to receive UITableView events. UITableViewDataSource is a protocol you implement to provide data for your UITableView.

So, with UITableViewDelagate protocol you will be able to response to events like: selection on your rows, editing and several others.

With UITableViewDataSource protocol you will be able to feed data into your table. Messages defined on this protocol will be called automatically by the UITableView class.

查看更多
戒情不戒烟
4楼-- · 2019-01-14 05:10

UITableViewDelegate

Serving as a table's delegate means you provide answers to requests about the layout of the table and about actions the user performs on the tableview. Layout methods include the tableview asking about the height of rows, headers, and footers, what the buttons should look like, etc. Action methods include the user selecting a row and beginning and ending the editing of a row.
   

UITableViewDatasource

Serving as a table's datasource means you provide data for the sections and rows of a table and you act on messages that change a table's data. The datasource is asked for the data for a cell when the table is drawn, is told that the user has asked to delete a row, and is told the new value of a row that the user has edited.

查看更多
5楼-- · 2019-01-14 05:23

The data source adopts the UITableViewDataSource protocol and the delegate adopts the UITableViewDelegate protocol. UITableViewDataSource has one optional method through which the data source tells the table view how many sections it has (the default is one); it also has a required method through which it tells the table view how many rows are in each section. The UITableViewDelegate protocol declares a method that the delegate must implement to return a cell object that the table view uses when drawing a particular row. (“Table View Cells” gives more detail about this delegate task.) It also allows the delegate to modify visible aspects of the table view. Both protocols also include optional methods for responding to selections and taps on accessory views and for managing the insertion, deletion, and reordering of cells.

Learn basic at first! - TableView Guide

查看更多
登录 后发表回答