UITableView和NSFetchedResultsController行删除错误

时间:2015-05-21 17:42:34

标签: ios uitableview swift

我试图以这种方式从UITableView删除一行:

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        // Delete the row from the data source
        let itemToDelete: Device = fetchedResultsController.objectAtIndexPath(indexPath) as! Device
        (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext?.deleteObject(itemToDelete)
        self.fetchedResultsController.performFetch(nil)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    }
}

当我跑步时,我收到此错误:

Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (0) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).

0 个答案:

没有答案