Created
July 28, 2016 17:10
-
-
Save frankchang0125/3053ff94c262aaa4e5d28a31415c192f to your computer and use it in GitHub Desktop.
Scroll to the offset after reloading tableView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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