This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge pull request #72 from cHoco/master

More consistent TUTableView scrolling behavior with maintainContentOffsetAfterReload
  • Loading branch information...
2 parents 4f0d1e8 + 90b1d69 commit ae84520199a41904dc4e26661cd0c88feb463d77 @joshaber joshaber committed Sep 17, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/UIKit/TUITableView.m
View
@@ -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;
@@ -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) {

0 comments on commit ae84520

Please sign in to comment.