美文网首页
UITableView reloadData() 数据滚动到顶部

UITableView reloadData() 数据滚动到顶部

作者: NightRainBreeze | 来源:发表于2019-08-14 18:10 被阅读0次

设置 UITableView 列表滚动

  • layoutIfNeeded 滚动到顶部
  self.tableView?.reloadData()
  self.tableView?.layoutIfNeeded()
  self.tableView?.setContentOffset(CGPoint(x: 0, y: 0), animated: false)
  • scrollsToTop 滚动到顶部
  self.tableView?.beginUpdates()
  self.tableView?.scrollsToTop = true
  self.tableView?.endUpdates()
  • scrollToRow 滚动到底部
  self.tableView?.scrollToRow(at: IndexPath(row: dataSource.count - 1, section: 0), at: .top, animated: true)
  • scrollToRow 滚动到指定位置
 // position 滚动到指定 row 位置
 // ScrollPosition .none  .top .middle .bottom
  self.tableView?.scrollToRow(at: IndexPath(row: position, section: 0), at: .top, animated: true)

相关文章

网友评论

      本文标题:UITableView reloadData() 数据滚动到顶部

      本文链接:https://www.haomeiwen.com/subject/lmenjctx.html