ios - 当我删除包含核心数据的单元格时,同一单元格显示两次

标签 ios swift xcode uitableview core-data

当我删除包含核心数据的单元格时,我遇到了一个问题。 当我在单元格之间删除时,已删除单元格的下一个单元格在下一个单元格之后变得相同。看起来像下面这样。 enter image description here

只是看起来像。当我出去并返回 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/

相关文章:

ios - Appium 错误 :main. js:错误:无法识别的参数:--no-session-override

ios - 文件是为 arm64 构建的,它不是链接的体系结构 (x86_64)

ios - ScrollView 在模拟器中无法正常工作

ios - Swift UITest 在 tableviewcell 中找不到 collectionview

iphone - 如果我从项目构建阶段的编译源中删除所有文件,会发生什么情况?

ios - Swift UIPickerView 使用 IBAction 触发 Segue

ios - 更新后在 Firebase 中查找项目的旧值

ios - 选中单元格时隐藏圆形uiview

ios:<错误>:CGAffineTransformInvert:奇异矩阵

ios - iPhone 6 应用调整大小