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的官方示例

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容