Swift ios 9: Section header change position after reload data

后端 未结 7 1141
我在风中等你
我在风中等你 2021-01-17 14:53

I have plain UITableView with many sections and rows. Sections work fine. But sometimes after reload data of table, section change position. For example it was happened when

7条回答
  •  没有蜡笔的小新
    2021-01-17 15:02

    It looks like the issue in estimated height for your table view cells. Due to internal optimisations system calculates the height of absent cells based on estimated height value, that's why it can position your headers on wrong calculated height (like real cells bigger or smaller than their estimated size). It usually happens when you call reloadData() in the middle of the list. As a proper solution you should avoid calling reloadData() when you want to update the content of the list with second page for example. So you should use tableView.beginUpdates() and tableView.endUpdates() and update items collection for table view. There is also new closure based API performBatchUpdates (just like it was for UICollectionView), but it's available from iOS 11.

    Hope it may help to find proper solution for you

提交回复
热议问题