LoginSignup
66

More than 5 years have passed since last update.

UIRefreshControlで引っ張って更新をする

Last updated at Posted at 2013-05-02

facebookなどのアプリでよく見る、引っ張って更新(Pull to Refresh)を実装する方法です。

実装はかなり簡単です。UIRefreshControlのインスタンスをUITableViewControllerのUITableViewControllerにセットするだけです。
更新処理はUIRefreshControlのaddTarget:action:forControlEvents:でアクションを設定すればOKです。

- (void)viewDidLoad
{
    [super viewDidLoad];

UIRefreshControl *refreshControl = [[UIRefreshControl alloc]init];

// 更新アクションを設定
[refreshControl addTarget:self action:@selector(onRefresh:) forControlEvents:UIControlEventValueChanged];

// UITableViewControllerにUIRefreshControlを設定
self.refreshControl = refreshControl;
}

- (void)onRefresh:(id)sender
{
    // 更新開始
    [self.refreshControl beginRefreshing];

    // 更新処理をここに記述

    // 更新終了
    [self.refreshControl endRefreshing];
}

引っ張った時にでてくるテキストとかもいろいろ変更できるようです。

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
66