0

I just added a normal UIRefreshControl to my UITableView but it does a weird reframe animation when pulling.

Anyone knows why can this happen? i'm not modifying the tableView insets or anything.

EDIT: The tableView is a subview in a UIViewController (not a UITableViewController). Added as:

self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.tintColor = [UIColor blackColor];
[self.refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:self.refreshControl];
saky
  • 135
  • 1
  • 6
  • 1
    Can you show us the code of `UITableViewController`? Or show how you setup the table view in a storyboard? – Michał Ciuba Aug 05 '14 at 13:59
  • Edited the question, not using a UITableViewController ;) – saky Aug 05 '14 at 14:06
  • Well, it's a standard way to setup a refresh control. How do you create your table view, then? – Michał Ciuba Aug 05 '14 at 14:14
  • I do everything in code, nothing strange i think... `self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds] [self.view addSubview:self.tableView];` – saky Aug 05 '14 at 14:16

1 Answers1

1

From the UIRefreshControl docs:

Because the refresh control is specifically designed for use in a table view that's managed by a table view controller, using it in a different context can result in undefined behavior.

You can add a "dummy" UITableViewController and assign tableView to it (credits to this answer).

UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = self.myTableView;
tableViewController.refreshControl = self.refreshControl;

Or alternatively, you can use a custom replacement for the UIRefreshControl - there are many of them on GitHub. This way you can also customize the refresh control if you want to.

Community
  • 1
  • 1
Michał Ciuba
  • 7,876
  • 2
  • 33
  • 59
  • I tried with a dummy `UITableViewController` and it does not work (same weird animation). I also tried with other custom UIRefreshControl, and they do work correctly, but i want to know why the UIRefreshControl is doing that and if there is a way to fix it to use it... – saky Aug 05 '14 at 15:34
  • On the animated GIF I can see that you use kind of a table header (?) - maybe this is the cause? Or maybe try to create UITableView in `loadView` method of `UIViewController` instead of adding it a subview to self.view? I'm just guessing here, I don't know why it doesn't work knowing only the code you posted – Michał Ciuba Aug 06 '14 at 07:21
  • The blue thing is a NavBar – saky Aug 06 '14 at 10:16