Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a UITableView from scrolling up vertically?

I'm using EGORefreshTableHeader in conjunction with a static cell (defined in a nib) in a UITableView.

I'd like to be able to scroll the tableview down to trigger the EGORefreshTableHeader and thus refresh the data in the static cell. BUT, as the static cell is sized to fit perfectly in the window, I want to prevent folks from being able to scroll up.

Is there a way to do this?

like image 844
wgpubs Avatar asked Jan 20 '23 01:01

wgpubs


1 Answers

Try this:

CGFloat a;

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    a = scrollView.contentOffset.y;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y > a) 
    {
        [scrollView setScrollEnabled:NO];
        [scrollView setContentOffset:CGPointMake(0, a)];
    }
    [scrollView setScrollEnabled:YES];
}
like image 104
kai Avatar answered Jan 30 '23 00:01

kai