UIRefreshControlを使って”引っ張って更新”処理を実装

リスト画面で良く見かける”引っ張って更新”処理ですが、iOSでは標準のUIコンポーネントで”UIRefreshControl”というのが用意されています。
しかもUITableViewControllerではプロパティとして既に定義済みなので、UITableViewControllerを使用する場合は簡単に使用する事ができます。

viewDidLoad

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

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

onRefresh

// 開始
[self.refreshControl beginRefreshing];

// 終了
[self.refreshControl endRefreshing];

以上。

タイトルとURLをコピーしました