Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios 10 NSfetchedResultController在删除多行时不设置动画_Ios_Core Data_Nsfetchedresultscontroller - Fatal编程技术网

ios 10 NSfetchedResultController在删除多行时不设置动画

ios 10 NSfetchedResultController在删除多行时不设置动画,ios,core-data,nsfetchedresultscontroller,Ios,Core Data,Nsfetchedresultscontroller,您好,我正在使用一个带有CoreData和NSfetchedResultController的应用程序。删除多行时,我遇到了一个奇怪的问题。删除动画适用于IOS 9,但适用于IOS 10。现在有了动画(无论选择什么动画,细胞都会消失) 这里是我的fetchedResultController(来自主详细信息模板) 要在IOS 10上恢复动画吗?任何帮助都是非常感谢的。谢谢 // MARK: - Fetched results controller var fetchedResultsContr

您好,我正在使用一个带有CoreData和NSfetchedResultController的应用程序。删除多行时,我遇到了一个奇怪的问题。删除动画适用于IOS 9,但适用于IOS 10。现在有了动画(无论选择什么动画,细胞都会消失)

这里是我的fetchedResultController(来自主详细信息模板)

要在IOS 10上恢复动画吗?任何帮助都是非常感谢的。谢谢

// MARK: - Fetched results controller

var fetchedResultsController: NSFetchedResultsController<Event> {
    if _fetchedResultsController != nil {
        return _fetchedResultsController!
    }

    let fetchRequest: NSFetchRequest<Event> = Event.fetchRequest()

    // Set the batch size to a suitable number.
    fetchRequest.fetchBatchSize = 20

    // Edit the sort key as appropriate.
    let sortDescriptor = NSSortDescriptor(key: "timestamp", ascending: false)

    fetchRequest.sortDescriptors = [sortDescriptor]

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".
    let aFetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext!, sectionNameKeyPath: nil, cacheName: "Master")
    aFetchedResultsController.delegate = self
    _fetchedResultsController = aFetchedResultsController

    do {
        try _fetchedResultsController!.performFetch()
    } catch {
         // Replace this implementation with code to handle the error appropriately.
         // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
         let nserror = error as NSError
         fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
    }

    return _fetchedResultsController!
}    
var _fetchedResultsController: NSFetchedResultsController<Event>? = nil

func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
    self.tableView.beginUpdates()
}

func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
    switch type {
        case .insert:
            self.tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)
        case .delete:
            self.tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)
        default:
            return
    }
}

func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
    switch type {
        case .insert:
            tableView.insertRows(at: [newIndexPath!], with: .fade)
            tableView.scrollToRow(at: newIndexPath!, at: .none, animated: true)
        case .delete:
            tableView.deleteRows(at: [indexPath!], with: .right)
        case .update:
            self.configureCell(tableView.cellForRow(at: indexPath!)!, withEvent: anObject as! Event)
        case .move:
            tableView.moveRow(at: indexPath!, to: newIndexPath!)
    }
}

func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
    self.tableView.endUpdates()
}
func deleteObjects(_ sender: Any?) {
        NSLog("test")

        let context = self.fetchedResultsController.managedObjectContext

        if (tableView.indexPathsForSelectedRows != nil) {

            let alert = UIAlertController(title: "Confirm delete?", message: "are your sure?", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { okAction in
                for selectedIndex in self.tableView.indexPathsForSelectedRows! {

                    context.delete(self.fetchedResultsController.object(at: selectedIndex))
                }

                do {
                    try context.save()

                } catch {
                    // Replace this implementation with code to handle the error appropriately.
                    // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                    let nserror = error as NSError
                    fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
                }
            }))

            alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))

            self.present(alert, animated: true, completion: nil)

        }else{
            let alert = UIAlertController(title: "Select rows to delete", message: "please select at least a row", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))

            self.present(alert, animated: true, completion: nil)

        }