LoginSignup
1
1

More than 5 years have passed since last update.

tableView.insertRowsでハマった

Last updated at Posted at 2019-01-20

どれだけセル更新しようと思って配列更新しても反映されなかったけどすごい初歩的なミスだった気がする。
雑だけど書いておく。

tableView.insertRows(at: [IndexPath(row: i, section: j )], with: UITableViewRowAnimation.*)で挿入(変更通知)する位置iと、
tableView:cellForRowAtでテーブルセルに表示する配列の要素位置iは揃える必要があって、そこに気づけなかった。
まあ当たり前だとは思うんだけど…

自分はinsertRowsで挿入する前に対象配列をappendで更新(=配列末尾に追加)してるにも関わらず、
insertRowsのIndexPathのrowに0を指定してたから、
いくら配列更新しても、配列の0番目要素がinsertRowされて、
無限に配列の0番目要素がセルに追加される形に…

なおappendで更新するならIndexPath(row: 配列.count-1, section: <任意>)とすればよい

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