2013年5月27日月曜日

[iOS]SIGABRT:'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'


新たなエラーがでてきました。TableViewでCellをupdateしようとしたときに起きたエラーです。

それまではCellの数がかわらないupdateだったため、

[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationFade];



で十分に対応できてました。

しかし、今回はCellの数に変更があるため、visibleCellsあるいはVisibleRowsだけの一部変更では対応できなくなったのが理由でした。

<対処法>
例に漏れず、こういうときは全体のtableViewに変更があるわけなので、

[self.tableView reloadData];


これで対応すると問題なくいけました。ちゃんちゃん