Adding Pull-to-refresh to Table View

Pull-to-refresh is a common data reloading pattern found in many application. In iOS, there is a UIRefreshControl that we can use easily to add this pull-to-refresh function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- (void)viewDidLoad {

  [super viewDidLoad];

  [self setUpUI];
  [self setUpSearchBar];

  // Set up pull to refresh.
  self.refreshControl = [[UIRefreshControl alloc] init];
  [self.tableView addSubview:self.refreshControl];
  [self.refreshControl addTarget:self action:@selector(refreshControlDidBegin:)
    forControlEvents:UIControlEventValueChanged];
}

- (void)refreshControlDidBegin:(UIRefreshControl* )refreshControl {
  [self syncData];
}

Comments