Skip to content

Instantly share code, notes, and snippets.

@setoh2000
Created March 1, 2012 21:39
Show Gist options
  • Save setoh2000/1953420 to your computer and use it in GitHub Desktop.
Save setoh2000/1953420 to your computer and use it in GitHub Desktop.
UITableViewでスクロール停止時に表示されるセルを予想する iOS5以降
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
UITableView *tableView = (UITableView *)scrollView;
int n = tableView.frame.size.height / _cellHeight;
if ((int)tableView.frame.size.height % (int)_cellHeight) n++;
for (int i = 0; i <= n; i++) {
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:CGPointMake(0, targetContentOffset->y + i * _cellHeight)];
NSLog(@"scrollViewWillEndDragging - indexPath = %d", indexPath.row);
}
}
@setoh2000
Copy link
Author

_cellHeightは事前にセルの高さを入れておくこと。
可変にするならindexPathからセルから求めて随時計算するようにすればよいかと。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment