iOS8 Swift:deleteRowsAtIndexPaths崩溃

iOS8 Swift:deleteRowsAtIndexPaths崩溃,第1张

iOS8 Swift:deleteRowsAtIndexPaths崩溃

使用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()}

这应该可以解决您的问题。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4908790.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存