Core DataのNSManagedObject
から派生したタイプProduct
のオブジェクトを削除しようとしましたが、オブジェクトを正常に削除することができます。それはtableView.deleteRows(at:with:)
の行でクラッシュしました。tableView.deleteRows(at:with :)毎回クラッシュしました
それで、クラッシュするたびに、私は再びアプリケーションを開きますが、オブジェクトは正常に削除されましたが、なぜそれがtableView.deleteRows(at:with:)
にクラッシュしたのか分かりません。
どうすれば修正できますか?
class ProductListInSection {
let sectionName: String
var productsInSection: [Product]
init?(sectionName: String, productInSection: [Product]){
guard !sectionName.isEmpty else {
return nil
}
self.sectionName = sectionName
self.productsInSection = productInSection
}
}
var categorySections: [ProductListInSection]
// ...
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
let element = self.categorySections[indexPath.section].productsInSection[indexPath.row]
AppDelegate.viewContext.delete(element)
do {
try AppDelegate.viewContext.save() // successfully removed.
} catch {
print("Fail: \(error)")
return
}
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic) // crashed here.
}
}
次のエラーメッセージである:
2017年4月21日15:54:42.159 POS [20241:2852960] ***でアサーション障害 - [のUITableView _endCellAnimationsWithContext:]、/ BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UITableView.m:1737
ありがとうございました。私はとてもばかげている。 –