Skip to content

Instantly share code, notes, and snippets.

@pronebird
Created April 30, 2016 19:34
Show Gist options
  • Save pronebird/5e2455c67b06bf182f7a8c66649df6ac to your computer and use it in GitHub Desktop.
Save pronebird/5e2455c67b06bf182f7a8c66649df6ac to your computer and use it in GitHub Desktop.
Capture target content offset when using scrollToRowAtIndexPath
//
// BaseTableView.m
//
// Created by pronebird on 1/12/16.
// Copyright © 2016 pronebird. All rights reserved.
//
@interface BaseTableView ()
@property (nonatomic) BOOL isCallingFromScrollToRowAtIndexPath;
@property (nonatomic) CGPoint scrollToRowOffset;
@end
@implementation BaseTableView
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated {
if(self.isCallingFromScrollToRowAtIndexPath) {
self.scrollToRowOffset = contentOffset;
}
[super setContentOffset:contentOffset animated:animated];
}
- (CGPoint)scrollToRowAtIndexPathAndReturnTargetOffset:(NSIndexPath *)indexPath
atScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated
{
[self scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
return self.scrollToRowOffset;
}
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated {
self.isCallingFromScrollToRowAtIndexPath = YES;
[super scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
self.isCallingFromScrollToRowAtIndexPath = NO;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment