UITableView Refresh without scrolling

后端 未结 12 699
时光说笑
时光说笑 2021-02-03 23:06

I have a _TableView with items , and I want to set automatic refresh,and I don\'t want it to scroll on refresh , lets say user scrolled 2 pages down , and the refre

12条回答
  •  青春惊慌失措
    2021-02-03 23:35

    When you want to reload you have to

    self.tableView.reloadData()
    
    self.tableView.layoutIfNeeded()
    

    and also use this UITableViewDelegate

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
            return 'your maximum cell's height'
    }
    

    and your tableView will remain on the previous scroll position without scrolling

提交回复
热议问题