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