开发者

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 thi开发者_运维问答nk 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

Issue scrolling table view with content inset

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.

Issue scrolling table view with content inset


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.


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?


It seems to me that the tableView is doing exactly what you're asking of it. I don't think this is a bug at all.

You're moving the inset down from the top but you never bring it back up. You could try an else statement that reverses what you're doing in the if statement.

Also, have you considered changing your view hierarchy? Could you take the tabs out of the tableView, put them at the top of the screen and have the tableView below? Then you wouldn't have to worry about setting the inset at all. Just a thought, I haven't seen the rest of the app.


Just set the contentOffset to a y point 1 pixel above or below and it won't do that.

 CGPoint pt = scrollView.contentOffset;
 scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);

 scrollView.contentOffset = CGPointMake(pt.x, pt.y-1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜