UITableView insert rows without scrolling

前端 未结 6 1382
我在风中等你
我在风中等你 2020-12-05 03:13

I have a list of data that I\'m pulling from a web service. I refresh the data and I want to insert the data in the table view above the current data, but I want to keep my

6条回答
  •  执笔经年
    2020-12-05 03:52

    For further spectators looking for a Swift 3+ solution:

    You need to save the current offset of the UITableView, then reload and then set the offset back on the UITableView.

    func reloadTableView(_ tableView: UITableView) {
        let contentOffset = tableView.contentOffset
        tableView.reloadData()
        tableView.layoutIfNeeded()
        tableView.setContentOffset(contentOffset, animated: false)
    }
    

    Called by: reloadTableView(self.tableView)

提交回复
热议问题