UITableView - scroll to the top

前端 未结 30 3103
南方客
南方客 2020-11-28 17:22

In my table view I have to scroll to the top. But I cannot guarantee that the first object is going to be section 0, row 0. May be that my table view will start from section

30条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 17:57

    I prefer the following, as it takes into account an inset. If there is no inset, it will still scroll to the top as the inset will be 0.

    tableView.setContentOffset(CGPoint(x: 0, y: -tableView.contentInset.top), animated: true)
    

提交回复
热议问题