UITableView - scroll to the top

前端 未结 30 3063
南方客
南方客 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 18:03

    Swift 4:

    This works very well:

    //self.tableView.reloadData() if you want to use this line remember to put it before 
    let indexPath = IndexPath(row: 0, section: 0)
    self.tableView.scrollToRow(at: indexPath, at: .top, animated: true)
    

提交回复
热议问题