Because tableView needs to jump to the top position, the contentOffset of tableView is set to (0,0). At this time, I suddenly found that when I just loaded the data, I could return to the top normally. After pagination, the contents of tableView did not return to the top for the first time, but returned to the upper-middle position indefinitely, but I can successfully return to the top for the second time.
Solution:
Perfect solution
Reason:
When the number of cells in tableView changes and is overloaded again, the value of contentOffset is calculated by estimating the height of each cell and the height of the header and footer, which is not an accurate value. After knowing the principle, the solution is simple, just turn off the system's own estimation.
EstimatedRowHeight is an estimated height, which is 0 before iOS 1 1. Under iOS 1 1, the default value is 44 (but at present, under ios 14, the login display is-1).
Let's talk about the details first.
If functableview (_ tableview: uitableview, indexpath: estimated height of rows at indexpath-> is implemented; The estimated height of the proxy CGFloat and estimatedRowHeight, the default height will be invalid. EstimatedRowHeight defaults to 0 before ios 10. I think people say that after ios 1 1, it defaults to 44, but I log in and find that it defaults to-1. Through the actual test, it is found that the value of-1 or 44 is not used in the actual calculation, which is about 17. However, if you want to prevent boundary jumps, you'd better implement a proxy to estimate the height and return a value as close as possible to the true height.
The original address of my blog.