我想從我的TableView刪除項目,但是當我向左滑動,並在單擊刪除,我得到這個錯誤:AppDelegate的錯誤,當從TableView中
這是代碼,我有,當我評論self.tableView.deleteRowsAtIndexPaths
線,一切工作正常。
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
if let index: NSIndexPath = indexPath {
self.tableView.beginUpdates()
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
self.configurations.delete(ProductDatabase.deleteProduct(self.products[index.row]))
loadProductsToListOrder()
self.tableView.endUpdates()
}
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
我搜查,發現這裏堆棧溢出這個beginUpdates
和endUpdates
。
謝謝。
更新
loadProductsToListOrder功能
func loadProductsToListOrder() {
self.products = ProductDatabase.listProduct(self.configurations.db!)
self.tableView.reloadData()
}
如果我在我的TableView一個元素,我沒有這個問題。如果我在TableView中有多個itens,就會發生。
更新2
是@harshayarabarla給了作品對我來說,因爲我忘記deleteRowsAtIndex前添加self.products.removeAtIndex(indexPath.row)
答案。
謝謝!
你的應用程序崩潰了!你有沒有得到任何崩潰日誌?把異常斷點看看它在哪裏崩潰 –
顯示方法加載產品!!! –
FUNC loadProductsToListOrder(){ self.products = ProductDatabase.listProduct(self.configurations.db!) self.tableView.reloadData() } –