美文网首页
coredata诡异的crash

coredata诡异的crash

作者: 无名氏_1 | 来源:发表于2015-11-17 20:38 被阅读259次

病情描述
使用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的官方示例

相关文章

网友评论

      本文标题:coredata诡异的crash

      本文链接:https://www.haomeiwen.com/subject/jxxlhttx.html