LoginSignup
20
16

More than 5 years have passed since last update.

iOSで下に引っ張って更新するやつの作り方

Posted at

概要

Twitterなどでよく見かける引っ張って更新するやつの実装方法です。
実装には「UIRefreshControl」を使用します。

実装

ロジックとしては、UIRefleshControlインスタンスを作成し、UITableViewに対してaddSubViewをするだけです。
以下そのコードとなります。

RefleshControlSample.m
- (void)refleshControlSetting
{
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self
                       action:@selector(onRefresh:)
             forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:refreshControl];
}

- (void)onRefresh:(UIRefreshControl *)refreshControl
{
    [refreshControl beginRefreshing];
    // ここの間に更新のロジックを書く
    [refreshControl endRefreshing];
}

参考

20
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
16