For example: first analyze the requirements: 1. Displays the cell with different heights, and the cell's UI interface according to the model's different states.
2. When clicking the cell's Cancel button, the corresponding cell will first hide the Cancel button and then change the cell's height.
Solve the first requirement according to the requirement, it takes two steps
When the model data attribute status [email protected] "2", the Cancel button is not displayed; status = @ "1", the Cancel button is displayed.
1. It is important to note that the reuse of cells has some effect on each side, so in the setter method of the custom cell's model,
Write the pseudo-code of the model setter method in the cell.m file:
if (status = = 1) { //cell add the corresponding UIButton }else if (status = = 2) { //If the previous step creates a button created in the cell exists, then the corresponding button is removed. That is, nil, otherwise it will appear reused }
2. In the controller to calculate the cell height corresponding to the proxy method
-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) section{ //The corresponding model shows the corresponding height , so the corresponding model needs to be obtained first, and the model can be obtained according to the property model in the cell, that is, the property of the model in the cell is obtained by customizing the cell's Object method.
when the corresponding property is obtained, the corresponding height is displayed according to the state of the attribute in the corresponding model. You need to know here to get the cell, not only through the tableview corresponding to the Indexpath, but also through the custom Cell object method to get the cell. return;}
The first requirement can be solved by the above two steps.
Second requirement: When clicking the cell's Cancel button, the corresponding cell will first hide the Cancel button and then change the cell's height.
There are two ways to listen for a button in a cell: the first defines the tag value of the button, gets it in the controller, then listens to the method, or writes the button's property in the cell.h to get cell.btn in the cell's data source proxy and then listens for the method.
The second approach is to create a proxy method in the cell, and when you click the button in the cell to listen for the button being clicked in the cell, then the corresponding proxy can be passed, such as the cell and the corresponding model.
So here's how it's going to work. Click on the corresponding row cell model passed, and then change the state of the properties in the model, reload the corresponding row of the cell.
Deep understanding of UITableView in IOS