当我删除包含核心数据的单元格时,我遇到了一个问题。 当我在单元格之间删除时,已删除单元格的下一个单元格在下一个单元格之后变得相同。看起来像下面这样。
只是看起来像。当我出去并返回 TableView 时,它被正确删除。 但是,当我删除最后一个单元格时,它看起来不错。效果很好!不仅仅发生这种情况(删除最后一个单元格)!
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
//FIXME: Delete
let quote:Quotes = quotes![indexPath.row]
self.context.delete(quote)
do {
try self.context.save()
self.quotes?.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
} catch let error {
print(error)
}
}
}
func controllerWillChangeContent(controller: NSFetchedResultsController<NSFetchRequestResult>) {
self.tableview.beginUpdates()
}
func controllerDidChangeContent(controller: NSFetchedResultsController<NSFetchRequestResult>) {
self.tableview.endUpdates()
}
我不知道出了什么问题,请告诉我这种情况:(
我的模拟器是v10.1,Xcode版本是8.2.1
最佳答案
Blow Code 对我有用!
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
//FIXME: Delete
let quote:Quotes = quotes![indexPath.row]
self.context.delete(quote)
do {
try self.context.save()
deleteRow(indexPath)
} catch let error {
print(error)
}
}
func deleteRow(indexPath : NSIndexPath){
self.quotes?.remove(at: indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
}
关于ios - 当我删除包含核心数据的单元格时,同一单元格显示两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42431589/