Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue scrolling table view with content inset

I am experiencing a weird scrolling issue and I was hoping someone could give me a hand in trying to identify why this is happening.

I have included the part of my code that I think is relevant to the question but am happy to update this post with whatever else is needed.

I have implemented a pull to refresh view in the tableview's content inset area. The refresh fires an Async NSURLConnection that pulls data from a webserver, parses the relevant information and refreshes the table as required.

This is where the refresh process kicks off:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

    if (scrollView.contentOffset.y <= - 65.0f && !self.reloading) {
        self.reloading = YES;
        [self reloadTableViewDataSource];
        [refreshHeaderView setState:EGOOPullRefreshLoading];
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.2];
        self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
        [UIView commitAnimations];
    }
}

Problem is if I start to scroll whilst the content inset is "visible" (i.e. during reload) I get this weird behaviour where my table sections do not scroll all the way to the top - see screenshot for a clear visual of what I am trying to describe here.

I have included a couple of screenshots below that clearly identify what is happening at the moment.

Has anyone experienced this before? Any ideas on what I should be looking at to try and fix it?

Many thanks in advance, Rog

alt text

And this is the result if I start scrolling the table. The orange bit at the top of the image is the actual navigation bar, where I would expect the table section (date 1 December 2010) to be.

alt text

like image 660
Rog Avatar asked Dec 06 '10 10:12

Rog


2 Answers

I assume you have something like if (self.reloading) return; in your scrollViewDidScroll method? You can add this to fix your problem:

if (self.reloading) {
    if (scrollView.contentOffset.y > -60.0 && scrollView.contentOffset.y < 0.0 && insetOnReload) {
        [self.tableView setContentInset:UIEdgeInsetsMake(-scrollView.contentOffset.y, 0.0, 0.0, 0.0)];
    }
    else if (scrollView.contentOffset.y >= 0.0 && insetOnReload) {
        [self.tableView setContentInset:UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)];
        insetOnReload = NO;
    }
    return;
}

Set insetOnReload to YES if you start the reloading.

like image 193
Black09 Avatar answered Oct 03 '22 01:10

Black09


Isn't this expected behavior? You set the contentInset of the tableView, which is the same as the scrollView in this example and thus the tableView insets its content by your given margin. The distance between the bottom of your tab-view and the section header is 60px (120px in your retina screenshot), so this matches exactly the contentInset.top value.

I assume you reset contentInset to 0.f after the refresh; does your wrong behavior disappear once your refresh is done?

like image 30
Pascal Avatar answered Oct 03 '22 02:10

Pascal