UITableViewDataSource protocol, uitableview

Source: Internet
Author: User

UITableViewDataSource protocol, uitableview


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 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;


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.