使用Xpre Core Data Master-
Detail模板项目很容易重现崩溃。通常,当您使用时
NSFetchedResultsController,您应该真正使用
NSFetchedResultsControllerDelegate(您已声明但不使用它)。
删除
tableView:commitEditingStyle:forRowAtIndexPath:方法中的这些行:
tableViewMain.beginUpdates()tableViewMain!.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: UITableViewRowAnimation.Fade)tableViewMain.endUpdates()
并将这些行添加到您的viewController类中:
func controllerWillChangeContent(controller: NSFetchedResultsController) { tableViewMain.beginUpdates()}func controller(controller: NSFetchedResultsController!, didChangeSection sectionInfo: NSFetchedResultsSectionInfo!, atIndex sectionIndex: Int, forChangeType type: NSFetchedResultsChangeType) { switch type { case .Insert: tableViewMain.insertSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade) case .Delete: tableViewMain.deleteSections(NSIndexSet(index: sectionIndex), withRowAnimation: .Fade) default: return }}func controller(controller: NSFetchedResultsController!, didChangeObject anObject: AnyObject!, atIndexPath indexPath: NSIndexPath!, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath!) { switch type { case .Insert: tableViewMain.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade) case .Delete: tableViewMain.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) case .Update: return //Should also manage this case!!! //self.configureCell(tableView.cellForRowAtIndexPath(indexPath), atIndexPath: indexPath) case .Move: tableViewMain.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) tableViewMain.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade) default: return }}func controllerDidChangeContent(controller: NSFetchedResultsController!) { tableViewMain.endUpdates()}
这应该可以解决您的问题。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)