iOS Edge learning--uitableview performance optimization

Source: Internet
Author: User

First, the cell recycling mode 1:

1 /**2 * When to call: every time a cell enters the field of view, it calls3  */4-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath5 {6     //0. Reusing identities7     //local variable modified by static: Only once, only one copy of memory is run during the whole program8     StaticNSString *id =@"Cell";9 Ten     //1. Find the cell that can be recycled based on the cell's identity to the cache pool OneUITableViewCell *cell =[TableView Dequeuereusablecellwithidentifier:id]; A  -     //2. If the cell is nil (the cache pool cannot find the corresponding cell) -     if(Cell = =Nil) { theCell =[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:id]; -     } -  -     //3. Overwrite Data +Cell.textLabel.text = [NSString stringWithFormat:@"testdata-%zd", Indexpath.row]; -  +     returncell; A}

Second, the cell recycling mode 2:--The disadvantage of this method is that only the system default style can be used

<1> Define a global variable

1 // definition Reuse identity 2 nsstring *id = @ "cell";

<2> registering a cell type for an identity

1 // register the cell in this method 2 -(void) viewdidload {3    [Super Viewdidload]; 4 5     // register a cell type for an identity 6     class ] Forcellreuseidentifier:id]; 7 }

<3> returning cells in the data source method

1-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath2 {3     //1. Go to the cache pool to find the cell4UITableViewCell *cell =[TableView Dequeuereusablecellwithidentifier:id];5 6     //2. Overwrite Data7Cell.textLabel.text = [NSString stringWithFormat:@"testdata-%zd", Indexpath.row];8 9     returncell;Ten}

Third, the cell recycling mode 3:

<1> set UITableView's dynamic prototypes Cell in storyboard

iOS Edge learning--uitableview performance optimization

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.