Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Commit

Permalink
Merge pull request #72 from cHoco/master
Browse files Browse the repository at this point in the history
More consistent TUTableView scrolling behavior with maintainContentOffsetAfterReload
  • Loading branch information
joshaber committed Sep 17, 2012
2 parents 4f0d1e8 + 90b1d69 commit ae84520
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/UIKit/TUITableView.m
Expand Up @@ -658,18 +658,24 @@ - (BOOL)_preLayoutCells
CGFloat previousOffset = 0.0f;
NSIndexPath *savedIndexPath = nil;
CGFloat relativeOffset = 0.0;

CGFloat resizingOffset = 0.0;
if ([self.nsView inLiveResize]) {
resizingOffset = (_lastSize.height - bounds.size.height);
}

if(_tableFlags.maintainContentOffsetAfterReload) {
previousOffset = self.contentSize.height + self.contentOffset.y;
} else {
if(_tableFlags.forceSaveScrollPosition || [self.nsView inLiveResize]) {
if(_tableFlags.forceSaveScrollPosition || resizingOffset) {
_tableFlags.forceSaveScrollPosition = 0;
NSArray *a = [INDEX_PATHS_FOR_VISIBLE_ROWS sortedArrayUsingSelector:@selector(compare:)];
if([a count]) {
savedIndexPath = [a objectAtIndex:0];
CGRect v = [self visibleRect];
CGRect r = [self rectForRowAtIndexPath:savedIndexPath];
relativeOffset = ((v.origin.y + v.size.height) - (r.origin.y + r.size.height));
relativeOffset += (_lastSize.height - bounds.size.height);
relativeOffset += resizingOffset;
}
} else if(_keepVisibleIndexPathForReload) {
savedIndexPath = _keepVisibleIndexPathForReload;
Expand All @@ -690,7 +696,7 @@ - (BOOL)_preLayoutCells

// restore scroll position
if(_tableFlags.maintainContentOffsetAfterReload) {
CGFloat newOffset = previousOffset - self.contentSize.height;
CGFloat newOffset = previousOffset - self.contentSize.height - resizingOffset;
self.contentOffset = CGPointMake(self.contentOffset.x, newOffset);
} else {
if(savedIndexPath) {
Expand Down

0 comments on commit ae84520

Please sign in to comment.