Skip to content

Instantly share code, notes, and snippets.

@frankchang0125
Created July 28, 2016 17:10
Show Gist options
  • Select an option

  • Save frankchang0125/3053ff94c262aaa4e5d28a31415c192f to your computer and use it in GitHub Desktop.

Select an option

Save frankchang0125/3053ff94c262aaa4e5d28a31415c192f to your computer and use it in GitHub Desktop.
Scroll to the offset after reloading tableView
/* We call layoutIfNeeded() immediately after reloadData()
* to force table view to perform layout immediately
* This is required to let the setContentOffset() in dispatch block to be executed
* after table view has completed performing its layout to scroll to the correct offset
* For further explanations, please see: http://goo.gl/BpzlA5 and http://goo.gl/6CH64b
*/
self.tableView.reloadData()
self.tableView.layoutIfNeeded()
dispatch_async(dispatch_get_main_queue(), {
/* Scroll to the previous saved position */
self.tableView.setContentOffset(self.contentOffset, animated: false)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment