私はこのテーマに関する記事の数があります知っていると私はそれらのほとんどを進めてきたが、私はまだ私のアプリがでクラッシュする原因tableViewCellを削除するときに私がいる問題を解決することはできませんエラーに従います。削除UITableViewCellの原因となるクラッシュ
Assertion failure in -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0})'
私は明示的に
を次のように削除のための私のコードがあるtableView.rowHeight = 140
を使用して、私の行の高さを設定
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
let object = self.datastore[indexPath.row]
do {
try self.realm?.write {
self.realm?.delete(object)
self.datastore.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .none)
}
} catch let error {
}
}
deleteAction.backgroundColor = .red
return [deleteAction]
}
これは、データストアから正しく項目を削除しません。私はmainThreadのdeleteを呼び出したり、dataSource全体を再読み込みするなど、さまざまなソリューションを試しましたが、それでもクラッシュします。
マイnumberOfRowsInSection
メソッドが呼び出されると、問題であるようには見えないように削除した後の行の正しい数を返すで取得します。私は、画像のダウンロードをキャンセルするように、細胞は、私が気づいた何
を削除された場合、私はそれがここにここに
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? Cell {
cell.image.kf.cancelDownloadTask()
}
}
KFをクラッシュだと思うものの、一般的な例外ブレークポイントの追加
はカワセミのライブラリですその私が
`tableView.dequeueReusableCell(withIdentifier: "Cell")`
代わりの tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
これはクラッシュしないので、それは私の解決策になるかもしれませんが、私はここで間違っているかを理解するために熱心です。私は、 'forIndexPath'メソッドは常にセルを返さなければならないが、このインスタンスではnilのためにクラッシュしていることを理解しています。
私はdidEndDisplayingに頼らない別のViewControllerで同じ削除コードがあります:セル法を、これはあなたがdidEndDisplayingにこの行を変更する必要が
試して優先度を変更するには: self.tableView.deleteRows(時:[indexPath]、と:.none)(時:indexPath.row) self.datastore.removeあなたのように動作しません – KKRocks
削除を実行する前にデータソースを編集する必要があります。それ以外の場合、無効な更新例外の原因となる不正確な数があります。**実際にはこれは動作しないことを確認しました。 – TommyBs
あなたのコードが停止した行はありますか? – KKRocks