The cell has a table view and a collection view of cell two, and the Factory mode is implemented in roughly the same way.
1. First introduce the cell factory of the table view
1): First create the cell base class Basetableviewcell that inherits from UITableViewCell, and use the custom cell in the project to inherit from this class (if you need a controller to control more than two! different! Then the second cell needs to be written in code).
2): Declare a method of setting data in the underlying cell class, and empty implement
-(void) Setdatawithmodel: (basemodel *) model;
3): Create the Cell factory class Factorytableviewcell and define a method to create a cell from the model
+ (Basetableviewcell *) Createtableviewcellwithmodel: (Basemodel *) model TableView: (UITableView *) TableView Indexpath :(Nsindexpath *) Indexpath
{
1. Get the name of the cell
NSString *name = Nsstringfromclass ([model class]);
2. Create a cell
Basetableviewcell *cell = [TableView dequeuereusablecellwithidentifier:name Forindexpath:indexpath];
}
4): Use of the plant
①: Registering the cell
[self. Mytableview registernib: [uinib nibwithnibname:@ "Readdetailcell" Bundle:nil] forcellreuseidentifier:nsstringfromclass([ Readdetaillistmodel class]);
②: Calling methods in the factory in the method of reusing cells
-(uitableviewcell *) TableView: (uitableview *) TableView Cellforrowatindexpath: (nsindexpath *) Indexpath
{
//1. Get model
Basemodel *model = self. Alllistarray[Indexpath. Row];
Basetableviewcell *cell = [factorytableviewcell createtableviewcellwithmodel: Model TableView: TableView indexpath: Indexpath];
[Cell Setdatawithmodel: Model];
return cell;
}
Cell's Factory mode