Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table view content jumping down when using UIRefreshControl and setting contentInset

So I have standard subclass of UITableViewController with table view. Now I have set content inset to

self.tableView.contentInset = UIEdgeInsetsMake(40, 0, 0, 0);

I'm also using UIRefreshControl in standard way.

self.refreshControl = [[CTRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(loadData:) forControlEvents:UIControlEventValueChanged];

All works fine and smoothly if table view contains enough data that it scrolls(so content size height is more than table view's height). When there is not enough data in table (e.g. only 2 rows) then when I start to pull down it goes smoothly and then suddenly it jumps by about 20 points down. Same thing happens when I scroll other direction. It doesn't happen when there's no refresh control or when I don't change contentInset. Any ideas? All on iOS 6.

like image 298
Michal Avatar asked Aug 07 '13 16:08

Michal


1 Answers

You need to put the change of contentInset in an animation block like this...

[UIView animateWithDuration:0.2
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     self.tableView.contentInset = UIEdgeInsetsMake(40, 0, 0, 0);
                 }
                 completion:nil];

(Typed from memory so you may have to check code completion).

This should fix your problem.

like image 93
Fogmeister Avatar answered Sep 27 '22 19:09

Fogmeister