UITableViewDataSource protocol, uitableview
Preface:
In iOS development, table view UITableView is an important view for UI design.
What protocols do you need to comply with when using Table view UITableView?
<UITableViewDataSource,UITableViewDelegate>
UITableViewDataSource table View data source protocol, used to control the display content of the table view;
The UITableViewDelegate table view protocol is used to control the display of the table view, the height of each cell, and the head and end height of each partition;
This document describes the UITableViewDataSource protocol.
What are the methods for UITableViewDataSource protocol?
First, you must implement the following methods:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
This method is used to set the number of rows in each group of tableView;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
This method is used to return the cell, that is, to control the content returned by each row;
The preceding two methods must be implemented;
What about other options?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
Set Several partitions in tableView. If this parameter is not specified, the default value is 1;
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
Set the content of the partition header. The returned value is of the NSString type;
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
Similarly, this method sets the content at the end of the partition. The returned value is of the NSString type;
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
This method is used to control whether the Cell can be edited. If it is not implemented, all rows are considered editable;
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
This method is used to control whether the Cell can be moved. Only after implementation can the Cell be moved;
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
Returns the title of each partition;
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
Tell tableView which row corresponds to which group title;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
Save the changes when the cell is edited;
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
Cell exchange based on the number of rows;
The above is the method of all UITableViewDataSource protocols;