Created
September 20, 2012 00:48
-
-
Save kolinkrewinkel/3753301 to your computer and use it in GitHub Desktop.
Maintaining UITableView Scroll Position
This file contains 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
NSIndexPath *zeroPath = [self.tableView.indexPathsForVisibleRows objectAtIndex:0]; | |
STRPost *zeroPost = [self.fetchedResultsController objectAtIndexPath:zeroPath]; | |
CGRect originalPosition = [self.tableView rectForRowAtIndexPath:zeroPath]; | |
CGPoint oldContentOffset = self.tableView.contentOffset; | |
[self.managedObjectContext mergeChangesFromContextDidSaveNotification:note]; | |
NSIndexPath *newIndexPath = [self.fetchedResultsController indexPathForObject:zeroPost]; | |
CGRect newPosition = [self.tableView rectForRowAtIndexPath:newIndexPath]; | |
CGFloat offsetPosition = originalPosition.origin.y - oldContentOffset.y; | |
self.tableView.contentOffset = CGPointMake(0.f, (newPosition.origin.y - offsetPosition) + self.tableView.tableHeaderView.frame.size.height); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment