IOS UI Foundation -9.0 UITableView Basics

Source: Internet
Author: User

In iOS, the most common practice for tabular data presentation is to use UITableView. The UITableView inherits from the Uiscrollview, so it supports vertical scrolling and has excellent performance.

There are two styles of UITableView:

    • One column shows: Uitableviewstyleplain
    • Group display: uitableviewstylegrouped
TableView the process of displaying data 1. The following method of invoking a data source learns how many sets of data

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView;

2. Call the following method of the data source to know how many rows of data each group has

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section;

3. Call the following method of the data source to know what each row shows

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath;

Common Properties
    //Color of table row linesSelf.tableView.separatorColor = [Uicolor colorwithred:255/255.0Green255/255.0Blue0Alpha255/255.0]; //Displays the style of the table row lines, uitableviewcellseparatorstylenone as no linesSelf.tableView.separatorStyle =Uitableviewcellseparatorstylesingleline; //the header control of the table (which displays directly at the top of the table) is typically used to display adsSelf.tableView.tableHeaderView =[UIButton Buttonwithtype:uibuttontypecontactadd]; //the bottom control of a table, typically used to load more dataSelf.tableView.tableFooterView = [[Uiswitch alloc] init];
Cell Reuse Code UITableViewCell has a NSString *reuseidentifier property that can be set reuseidentifier when initializing UITableViewCell by passing in a specific string identifier ( Generally used UITableViewCell class name). When UITableView requires DataSource to return UITableViewCell, a string is first identified to the object pool to find the corresponding type of UITableViewCell object, if there is, reuse, if not, The string identifier is passed in to initialize a UITableViewCell object
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//1. Define the identity of a cell. static modifier local variable: The local variable can be guaranteed to allocate only one storage space once (initialize only once)      StaticNSString *id =@"Mjcell"; //2. Remove the cell from the cache poolUITableViewCell *cell =[TableView Dequeuereusablecellwithidentifier:id]; //3. If there is no cell in the cache pool      if(Cell = =Nil) {Cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; }        //4. Set the properties of the cell ...      returncell;}
Right Index bar

Already have the corresponding data source, implementation can

/* * *   */-(Nsarray *) Sectionindextitlesfortableview: (UITableView *)    tableview{return [ Self.groups Valueforkeypath:@ "title"];}

Effect:

Refresh
    // Refresh All      [Self.tableview reloaddata];         // local refresh, row refers to the first few lines, insection refers to the group    Nsindexpath *path = [Nsindexpath indexpathforrow:row insection:0];    [Self.tableview Reloadrowsatindexpaths:@[path] withrowanimation:uitableviewrowanimationbottom];

IOS UI Foundation -9.0 UITableView Basics

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.