Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Section Headers in UITableView when inset of tableview is changed

I have implemented a "Pull to refresh" in my tableView like the iPhone app Twitter or Facebook.
My tableView has sections with head views. When the tableView is in "Refresh mode", so when I pulled the tableView to refresh, I set the contentInset of the tableView to display the tableView a certain way. At this moment, if I push the tableView up, the headers of the UITableView are not anymore scrolling to the top of the UITableView. See the following screenshots:

screenshot 1

screenshot 2

How can I fix that to make the headers scroll like expected?

Thanks!

like image 294
MartinMoizard Avatar asked Mar 28 '11 23:03

MartinMoizard


1 Answers

I had the same problem when using contentInset and fixed it by adding code to scrollViewDidScroll: to update the contentInset dynamically while in the "loading" state.

if( refreshState == kLoading ) {
    if( scrollView.contentOffset.y >= 0 )
        scrollView.contentInset = UIEdgeInsetsZero;
    else
        scrollView.contentInset = UIEdgeInsetsMake( MIN( -scrollView.contentOffset.y, kPullHeight ), 0, 0, 0 );
}       
like image 161
tgaul Avatar answered Oct 14 '22 10:10

tgaul