The effect we want is probably the following:
When we choose a cell, we are going to change its height and animate it.
How do we achieve this effect? We mainly need to use the following two methods:
-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
Two methods control the height of the cell and what happens when the cell is selected.
In our first approach, we need to implement some of the heights we want:
-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {if (the Indexpath is selected) { return 60 * 2.0;} return 60;}
In the second method, we control what we want to happen when the cell is clicked, and the "Big star code" we want to explore today is in it ~ ~
-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath {[TableView Deselectrowatindexpath:indexpath animated:true];//Gets the current Indexpath and determines if the corresponding cell is selected //The most magical place!! [TableView beginupdates]; [TableView endupdates];}
So why is there something magical happening here?
Let's focus on this line of code: [TableView beginupdates];
This line of code is interpreted in the documentation to allow TableView to insert, delete, or reload the cell
See here everyone should be suddenly understood, right? It turns out that when we click on a cell we reload our tableView again, but it's a completely different style from [TableView Reloadata], Reloaddata This method will allow the TableView to reload as a whole. The equivalent is the action on the TableView, and the beginupdates is just acting on the cell!
Well, you should already see the effect, if you still want to be able to read all our code, can be obtained by the following link ~ ~
Http://www.locassa.com/wp-content/uploads/2011/05/AnimatedTableViewCell.zip
TableView change cell height with animation effect