【iOS】UITableViewにプルリフレッシュ機能を付ける
UIRefreshControl
テーブルビューを引っ張って、データを更新する機能を付けたいと思って調べていたのですが、ライブラリを使わなくても簡単に実装できることが判明!
そこで見つけたのが、iOS6から使えるようになったUIRefreshControl
でした!(知らなかった...)
UIRefreshControl Class Reference
実装自体はすぐにできたので、リファレンスは見なくてもいいかもしれない。
手順
UITableViewにUIRefreshControlをaddSubView
let refreshControl = UIRefreshControl() refreshControl.addTarget(self,action:"refreshControlAction:",forControlEvents:UIControlEvents.ValueChanged) refreshControl.tintColor = UIColor.redColor() myTableView.addSubview(refreshControl)
処理を実装
func refreshControlAction(refreshControl: UIRefreshControl) { /* なんらかの処理 */ //処理後にぐるぐる回っているのを消す refreshControl.endRefreshing() }
これだけでできるんですね。感動しました...