when using TableView, it is very easy to have the data duplication problem of the cell, so the solution is sorted out, later it is convenient to use, and also hope to help everyone.
the reuse of the first cell
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath
UITableViewCell *cell = [TableView dequeuereusablecellwithreuseidentifier:kidentifier forIndexPath:indexPath];
return cell;
}
This type of multiplexing can be used in the following ways when data duplication occurs
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath
{
UITableViewCell *cell = [TableView dequeuereusablecellwithreuseidentifier:kidentifier forIndexPath:indexPath];
For (UIView *view in cell.subviews) {
if (view) {
[view Removefromsuperview];
}
}
return cell;
}
the reuse of the second cell
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath
{
UITableViewCell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:kidentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstylesubtitle Reuseidentifier: Cellidentifier];
}
return cell;
}
When you use this method to reuse the cell, there is duplication of data, you can use the following methods to solve 1
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath
{
// Defines a unique identity
static nsstring *cellidentifier = @ "Cell";
Creating a cell instance by Indexpath each cell is a separate
uitableviewcell *cell = [TableView Cellforrowatindexpath:indexpath];
if (!cell) {
cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstylesubtitle Reuseidentifier: Cellidentifier];
}
return cell;
}
2
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: ( Nsindexpath *) Indexpath {//define cell identity each cell corresponds to one's own identity nsstring *cellidentifier = [NSString stringwithformat:@] C
Ell%ld%ld ", Indexpath.section,indexpath.row];
UITableViewCell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:cellidentifier]; if (!cell) {cell = [UITableViewCell alloc]initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentif
IER];
} return cell; }