Reuse of 1.cell
The so-called cell reuse is that when the view is loaded, only the cell in the current view is created, or a bit more than the current view, when the view scrolls, the cell that rolls out the screen is put into the cache, and the cell that rolls into the screen gets the cell from the cache according to identifier. This repeats itself so that only fixed cell objects are created, saving memory.
Here's the code for reusing cells:
1. Defining identity for reuse
static NSString *reuseid = @ "TG";
2, retrieving the reuse cell from the cache
Cztgcell *cell = [TableView Dequeuereusablecellwithidentifier:reuseid];
3. Determine if cell is equal to nil to create cell
if (cell = = nil) {
cell = [[[NSBundle mainbundle]loadnibnamed:@ "Cztgcell" Owner:nil Options:nil]lastobject];
}
return cell;
2. Why define a reuse identifier when it is defined as a static
The number of cell calls is quite large, creating multiple identifier objects, while static variables create only one chunk of memory, saving memory space.
The point of note for the 3.cell init method
Overriding the Init method, when adding a child control, in this method, you need to set the control's one-time property, the so-called one-time property, refers to the size of the text, such as the color of the text ah, such as fixed values, because these properties and data do not have a relationship, improve performance.
Note: To set the control's frame, the frame headview directly in the Init method has no effect, so to set the frame of each child control in the Layoutsubviews method, the method must override the parent class's method.
4.cell reuse, not only to overwrite the data, but also to overwrite the corresponding state, or reuse will be the state and data will be reused
Reuse Workaround: Override the model's set method to overwrite the data and state.
The problem of 5.cell row height
The row height is computed several times before the cell is created, and if the row height is fixed, use the following proxy method sparingly, as it will call and calculate the row height multiple times, using the TableView RowHeight property
-(CGFloat) TableView: (UITableView *) TableView Estimatedheightforrowatindexpath: (Nsindexpath *) Indexpath;
The optimization of cell in UITableView