1

I have created a UIRefreshcontrol without a TableViewController. My question is how I would end it inside another method? This is how I created it;

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
    [_tableView addSubview:refreshControl];

3 Answers3

8

I discovered with help from @Justin Paulsson that this could be done;

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
    [_tableView addSubview:refreshControl];

-

-(void) handleRefresh:(UIRefreshControl *)controller
    {
        //Refresh code
        controller.endRefreshing;
    }
0

The documented way is using an UITableViewController. Anything else can work, but as it's not documented, it may break on next iOS versions.

I'd just use an UITableViewController in your case.

Marcelo
  • 9,916
  • 3
  • 43
  • 52
  • Yes I understand that would be a preferred way, but how would I do that? I'd prefer to keep it this way, and end it somehow still. – Daniel Wallman Apr 03 '13 at 15:10
  • 1
    To keep using the way you're trying, you need to store a reference of `refreshControl` in a property or ivar, so you can use it later to call `endRefreshing`. – Marcelo Apr 03 '13 at 15:14
  • 1
    or just use `[controller endRefreshing]` as the `handleRefresh:` passes a reference to the `UIRefreshControl` – Justin Paulson Apr 03 '13 at 15:25
  • Sure. I haven't seen that it's passed to `handleRefresh:`. – Marcelo Apr 03 '13 at 17:40
0

It turns out that UIRefreshControl doesn't require a UITableView at all. refreshControl is a property of UIScrollView. You can set it on anything that inherits from UIScrollView, which includes UITableView of course, but also other classes such as UICollectionView.

Nate Cook
  • 8,395
  • 5
  • 46
  • 37