概要
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];
}