UITableView Pagination

advertisements

My app has custom UITableView cells. I want to show only one cell at a time - next cell should show partially. In ScrollView you can set isPagingEnabled to YES.

But how can i do above in UITableView?

Thanks


Note that UITableView inherits from UIScrollView, so you can set pagingEnabledto YES on the table view itself.

Of course, this will only work if all cells and the table view itself are of the same height.

If you want to always have a cell start at the top of the table view after scrolling, you could use a UIScrollViewDelegate and implement something like this.

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
                     withVelocity:(CGPoint)velocity
              targetContentOffset:(inout CGPoint *)targetContentOffset
{
  UITableView *tv = (UITableView*)scrollView;
  NSIndexPath *indexPathOfTopRowAfterScrolling = [tv indexPathForRowAtPoint:
                                                       *targetContentOffset
                                                 ];
  CGRect rectForTopRowAfterScrolling = [tv rectForRowAtIndexPath:
                                             indexPathOfTopRowAfterScrolling
                                       ];
  targetContentOffset->y=rectForTopRowAfterScrolling.origin.y;
}

This lets you adjust at which content offset a scroll action will end.