31
35

More than 5 years have passed since last update.

TableViewの指定行だけを更新

Last updated at Posted at 2015-07-14

タップした行だけを更新する

swift
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath:NSIndexPath)
{
 // *** ここで行に表示するデータを更新する ***

  // 指定行のみ更新
  self.myTable.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
}

指定の行を更新する

カスタムセル内のボタンをタップして、同セルのラベルに表示された数字をインクリメントしたときに、その行だけを更新したい。

swift
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell
{
  // カスタムセル内ボタンのtagに行番号を設定 
  // カスタムセル内ボタンにaddTargetで「cellButton_Click」を追加
}

@IBAction func cellButton_Click(myButton: UIButton)
{
  // カスタムセルに紐付いてる情報を更新

  // カスタムセル内ボタンのtagから行番号を取得
  let row = myButton.tag
  // 対象行だけ更新
  let row = NSIndexPath(forRow: self._currentRow, inSection: 0)
  self.myTable.reloadRowsAtIndexPaths([row], withRowAnimation: UITableViewRowAnimation.Fade)
}

31
35
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
31
35