Transfer from http://www.cnblogs.com/ios8/p/ios-cell.html
Http://www.itnose.net/detail/6154013.html
One. Clear Cache
The cell in the TableView table has a reuse mechanism, which is a good thing to avoid opening up a lot of space memory. But sometimes we don't want it to reuse the cell, which can be solved with the following code.
Put this code in:
-(UITableViewCell *) TableView: (uitableview *) TableView Cellforrowatindexpath: (nsindexpath *) indexpath{ This function will do just fine.
- Clear the cell cache
- Nsarray *subviews = [[Nsarray alloc] initWithArray:cell.contentView.subviews];
- For (UIView *subview in subviews) {
- [Subview Removefromsuperview];
- }
Two. The general configuration is as follows when the range shown in the TableView is exceeded and the content displayed is repeated
This configuration is more than the contents of the page will appear repeatedly-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{ //defines a unique identifier for the static nsstring *cellidentifier = @ "Cell"; Create a cell instance with a unique identity uitableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; Determine null initialization -(the previous cell will be reused if the page is pulled beyond the main page content, and will not be initialized again) if (!cell) { cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; } Simple data configuration for cell Cell.textLabel.text = @ "text"; Cell.detailTextLabel.text = @ "text"; Cell.imageView.image = [UIImage imagenamed:@ "4.png"]; return cell;} The following 3 scenarios can be used to resolve
Scenario one cancels the cell reuse mechanism, and creating a cell via Indexpath will resolve the recurring display problem but it's a bit more tight than the big data.
Scenario one by not allowing him to reuse the cell to resolve the duplicate display-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: ( Nsindexpath *) indexpath{ //define a unique identity static nsstring *cellidentifier = @ "Cell"; Creating a cell instance from Indexpath each cell is a separate uitableviewcell *cell = [TableView Cellforrowatindexpath:indexpath]; Determine null initialization -(the previous cell will be reused if the page is pulled beyond the main page content, and will not be initialized again) if (!cell) { cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; } Simple data configuration for cell Cell.textLabel.text = @ "text"; Cell.detailTextLabel.text = @ "text"; Cell.imageView.image = [UIImage imagenamed:@ "4.png"]; return cell;}
Scenario two allows each cell to have a corresponding identity this will also make the cell unusable, so it will not be repeated display content more memory consumption is also more than a similar
Scenario two also by not allowing him to reuse the cell to resolve the duplicate display is different for each cell corresponding to an identity-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{ //define cell ID each cell corresponds to one of its own identity nsstring *cellidentifier = [NSString stringwithformat:@ "Cell%ld%ld", Indexpath.section,indexpath.row]; Create a cell instance with different identities uitableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; Determine null initialization -(the previous cell will be reused if the page is pulled beyond the main page content, and will not be initialized again) if (!cell) { cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; } Simple data configuration for cell Cell.textLabel.text = @ "text"; Cell.detailTextLabel.text = @ "text"; Cell.imageView.image = [UIImage imagenamed:@ "4.png"]; return cell;}
Scenario three only the last display of the cell content is not empty, and then all its sub-views are deleted, the same as the cell alone and then with the new data to resolve the duplicate display
Scenario three when the page pulls the need to display the new data, the last cell to delete it can be customized cell this scheme to avoid repeated display, and reuse the cell relative memory management is the best solution before the two relatively consumption of memory-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//define unique identity static NSString *cellid Entifier = @ "Cell"; Create a cell instance with a unique identity uitableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; The decision to initialize is null-(when the pull page displays more than the main page content, the previous cell is reused instead of being initialized again) if (!cell) {cell = [[UITableViewCell alloc]initwithstyl E:uitableviewcellstylesubtitle Reuseidentifier:cellidentifier]; } else//when the page is pulled, when the cell exists and the last one exists to delete it, a unique cell is configured to avoid {while ([Cell.contentView.subviews Lastobje CT] = nil) {[(UIView *) [cell.contentView.subviews lastobject] removefromsuperview]; }}//To cell for simple data configuration Cell.textLabel.text = @ "text"; Cell.detailTextLabel.text = @ "text"; Cell.imageView.image = [UIImage imagenamed:@ "4.png"]; return cell;}
The above are personal understanding, I am also a rookie, there is no understanding of the place I hope you point out, but also hope to be able to help you a certain!! Thank you!
iOS development cell reuse after the content is garbled