Scenario Description:
Sometimes we want to update the data for one cell, and it's common practice to update the entire cell with the Reloaddata method. However, it is not applicable to some situations or it is more troublesome to realize it. For example, this simple "point-and-click" cell
The hero's profile is replaced with "Click to view Details" and the download button is set to hidden when it is not opened.
In this case, if the data is reload the entire table at the point of opening, the table will revert to an open state because of the overloaded data.
Steps to resolve:
The advantage of using AutoLayout is that it allows the content to determine the height of the cell. So what is the way to adjust the cell height dynamically after the content has changed? Let's start with the constraint and write the constraint of the cell so that it adapts well to the state before and after the content changes. (see this article for TableView restrictions: http://www.cnblogs.com/zeyang/p/4457888.html)
But you'll find that no matter how you change it, the height of the cell will always be the same when the cell point is opened. Like this:
The reason is that we only tell the contents of the system cells to be changed, and the system thinks that the height of the cell is still the original height, so the content is compressed instead of the height of the cell. But Reloaddata will reload the entire table and not meet the requirements.
We have the following methods:
1: -(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{
2: //The most magical place!!
3: [TableView beginupdates];
4: [TableView endupdates];
5: }
6: -(void) TableView: (UITableView *) TableView Diddeselectrowatindexpath: ( Nsindexpath *) indexpath{
7: //The most magical place!!
8: [TableView beginupdates];
9: [TableView endupdates];
Ten: }
With these two words, the system recalculates the height of the cell each time the cell is selected, and when using AutoLayout, the cell can display the contents of the cell very well.
Reference Source:
[IOS] Change cell height with animation effect in TableView
Dynamically adjust cell height under iOS development--autolayout