objective-cuitableviewpaginationiphone-sdk-3.0

UITableView page size when paging enabled


I'm facing with a simple but tedious problem. What I'm trying to do is make an UITableView to page like an UIScrollView but enabling paging doesn't help me so much because I can't set page size so the tableview scrolls exactly of its height so it shows rows 1...10 or 11...20 and so on. What I'd like instead is that no cell remains clipped above or under the view when I scroll (thus paging) without having a sort of fixed range of shown cells.

Thanks a lot


Solution

  • Simple but efficient:

        - (void)scrollViewDidEndDecelerating:(UITableView *)tableView {
                int tomove = ((int)tableView.contentOffset.y%(int)tableView.rowHeight);
                if(tomove < tableView.rowHeight/2) [tableView setContentOffset:CGPointMake(0, tableView.contentOffset.y-tomove) animated:YES];
                else [tableView setContentOffset:CGPointMake(0, tableView.contentOffset.y+(tableView.rowHeight-tomove)) animated:YES];
        }
    
        - (void)scrollViewDidEndDragging:(UITableView *)scrollView willDecelerate:(BOOL)decelerate {
                if(decelerate) return;
    
                [self scrollViewDidEndDecelerating:scrollView];
        }