Skip to content

Instantly share code, notes, and snippets.

@JeremyXue77
Last active July 4, 2018 02:14
Show Gist options
  • Select an option

  • Save JeremyXue77/18a114c35a62e238a263b078f9971ac4 to your computer and use it in GitHub Desktop.

Select an option

Save JeremyXue77/18a114c35a62e238a263b078f9971ac4 to your computer and use it in GitHub Desktop.
func loadData(){
// 這邊我們用一個延遲讀取的方法,來模擬網路延遲效果(延遲3秒)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
// 停止 refreshControl 動畫
self.refreshControl.endRefreshing()
// 新建5筆假資料
for _ in 1...5 {
self.data.append(self.data.count + 1)
self.myTableView.insertRows(at: [[0,self.data.count - 1]], with: UITableViewRowAnimation.fade)
}
// 滾動到最下方最新的 Data
self.myTableView.scrollToRow(at: [0,self.data.count - 1], at: UITableViewScrollPosition.bottom, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment