LoginSignup
4
4

More than 5 years have passed since last update.

テーブルビューで、下に引っ張ったら更新するやつ (RubyMotion)

Posted at

Twitterなど色んなアプリでおなじみ、Pull to Refresh機能の実装。

UITableViewControllerの中で、UIRefreshControlを設定する。また、更新時の処理を
addTarget:action:forControlEvents:
を利用してセット。

items_controller.rb
class ItemsController < UITableViewController
  def viewDidLoad
    super

    # 略

    # refreshControlに、UIRefreshControlのインスタンスを設定
    self.refreshControl = UIRefreshControl.new.tap do |refresh|

      # 更新用のアクションを指定
      refresh.addTarget(self, action: 'refresh_items', forControlEvents: UIControlEventValueChanged)

    end

    # 略
  end

  def refresh_items

    # 更新開始の宣言
    self.refreshControl.beginRefreshing

    # (テーブル更新用の処理を記述)

    # 更新終了の宣言
    self.refreshControl.endRefreshing
  end
end

上記のように簡単に実装できる。めんどうなのは、更新処理の中身の方ですかねー。

4
4
0

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
4
4