UITableView - scroll to the top

前端 未结 30 3051
南方客
南方客 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:55

    Swift 5, iOS 13

    I know this question already has a lot of answers but from my experience, there is only one method that always works:

    tableView.scrollToRow(at: IndexPath(row: someArray.count - 1, section: 0), at: .bottom, animated: true)

    If you're working in async, tables that animate with keyboards, etc., the other answers will often scroll to the almost bottom, not the absolute bottom. This method will get you to the absolute end of a table every time.

提交回复
热议问题