UITableView requests cells with invalid indexPaths when using animated updates combined with automatic cell sizing

Originator:amadour
Number:rdar://26552741 Date Originated:31-May-2016
Status:Open Resolved:
Product:iOS SDK Product Version:9.3.2
Classification:Serious bug Reproducible:Always
 
Summary:
When using UITableView with autosizing cells, sometimes when using animated updates UITableView will call cellForRowAtIndexPath with an invalid (out of range) indexPath.
The attached project demonstrates the issue in a 100% reproducible way. The codepath is a bit contrived but the issue also frequently appears in the wild in an app that uses animated updates a lot.

Steps to Reproduce:
Key points are :
- use autosizing cells
- have cells off-screen whose exact height is not computed
- delete a cell in that off-screen range, and delete the following section, causing the updated range to come on-screen
- call endUpdates
as a result, UITableView tries to recompute the height for an indexPath that is now invalid, causing cellForRowAtIndexPath to be called with an invalid index after endUpdates has been called.

Expected Results:
cellForRowAtIndexPath: should never be called with an indexPath not in the range defined by the data source after endUpdates has been called

Actual Results:
cellForRowAtIndexPath: is called with an indexPath not in the range defined by the data source after endUpdates has been called

Version:
9.3.2

Notes:
Additional comments and a workaround are included in the demo project

Configuration:
any iOS device, the attached project is guaranteed to work on an iPhone 6 sized screen

Attachments:
'TableUpdatesCrash.zip' was successfully uploaded.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!