coredata诡异的crash

病情描述
使用coreData来驱动tableview,在代理方法
<code>- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller</code>
中调用<code>[self.tableView beginUpdates];</code>
<code>- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller</code>
中调用<code>[self.tableView endUpdates];</code>
同时在<code> - (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(nullable NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(nullable NSIndexPath *)newIndexPath</code>
调用tableview 的<code>insertRowsAtIndexPaths | deleteRowsAtIndexPaths</code> 等方法

现状:
1.删除cell 是动画无效(除最后一个)
2.使用DZNEmptyDataSet 异常crash
3.tableview 莫名奇妙cell 消息不见

原因
在<code>beginUpdates</code>和<code>endUpdates</code> 之间 , 也就是<code>controllerDidChangeContent...</code>方法中调用了 tableview 的reloaddata 方法
导致动画异常,和其他的crash(猜测)

备注
官方对<code>beginUpdates</code>和<code>endUpdates</code> 的描述

// Row insertion/deletion/reloading.

  • (void)beginUpdates; // allow multiple insert/delete of rows and sections to be animated simultaneously. Nestable
  • (void)endUpdates; // only call insert/delete/reload calls or change the editing state inside an update block. otherwise things like row count, etc. may be invalid.

coredata驱动tableview的官方示例

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容