2014年3月8日土曜日

UIRefreshControl を使って引っぱり更新をする。

iOS6で追加された引っぱり更新用のUIRefreshControlですが、先日私事でiOS5の呪縛から逃れたのでメモメモ。

※ちなみにiOSの6と7ではUIのビジュアルが違いますが、個人的にはiOS6の方が好きですが、手元に環境がないのでこの例はiOS7です。

UITableViewControllerにrefreshControlのプロパティがあるので、画面の初期化の時に設定。
UIControlEventValueChangedでイベントが取得出来るので、その設定も忘れずに。

// リフレッシュコントロール
[self setRefreshControl:[[UIRefreshControl alloc] init]];
[[self refreshControl] addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];

イベントの受け取りメソッドも定義。


- (void)refresh:(UIRefreshControl *)control
{
    // 回転開始
    [[self refreshControl] beginRefreshing];
    
    //
    // 処理
    //
    
    // 回転終了
    [[self refreshControl] endRefreshing];
}

「beginRefreshing」と「endRefreshing」でインジケーターの回転のタイミングを調節できるので、これでやりたい処理を挟みます。


こんな感じ。

0 件のコメント:

コメントを投稿