iOS 11 UITableView deleteRows crash

Crashes started occurring in iOS 11. In iOS 10 this works fine.


In a UITableViewCell, when swiping to the left to show the delete button, tapping on it would cause app to crash, with error “UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues: with userInfo (null)”


Interestingly, swiping all the way to the left for the same delete function worked as expected.


Other notes:

- This problem occurs in a UITableViewController. For some reason, in another screen which is a UIViewController subclass that contains a UITableView, a similar delete cell arrangement is implemented and there is no problem with delete button there.

- The problem is quite similar to this one: https://forums.developer.apple.com/thread/81591 however the solution there did not help in my case.

My code looks like:


    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        ..
        // Remove a CoreData entity, which triggers the other functions below to be called.
        ..
    }

    func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
        tableView.beginUpdates()
    }

    func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
        tableView.endUpdates()
    }

    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
            switch type {
            ..
            case .delete:
                tableView.deleteRows(at: [indexPath!], with: UITableViewRowAnimation.automatic)
            ..
        }
    }



Console logs (I added blank lines to make it more readable):


2017-09-26 22:33:35.301878+1000 MyApp[9977:3031908] *** Assertion failure in -[UITableView _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3694.4.18/UITableView.m:6813

2017-09-26 22:33:50.942028+1000 MyApp[9977:3031908] [error]
error: Serious application error. 
Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues: with userInfo (null)

CoreData:
error: Serious application error. 
Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues: with userInfo (null)

2017-09-26 22:33:50.952682+1000 MyApp[9977:3031908] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:'

*** First throw call stack:
(0x182807d38 0x181d1c528 0x182807c0c 0x183196c24 0x18bf38d84 0x18bdf35f4 0x1005cfed4 0x1005d0494 0x18509d5e0 0x185046ea4 0x185046d78 0x18509c6d8 0x18279a12c 0x1827996cc 0x182799430 0x1828169f4 0x1826d03e0 0x1830f0498 0x184fae348 0x18504ce18 0x184facb04 0x184fab778 0x10053572c 0x100534c44 0x1005d22bc 0x1005d23ac 0x18bf4de6c 0x18bf53ef8 0x18c312e00 0x18c57af90 0x18c57c3a0 0x18c63826c 0x18bc4b20c 0x18bc4b18c 0x18bc35f4c 0x18bc4aa80 0x18bc4a5a0 0x18bc45a70 0x18bc17078 0x18c556f98 0x18c559408 0x18c552574 0x1827b0358 0x1827b02d8 0x1827afb60 0x1827ad738 0x1826ce2d8 0x18455ff84 0x18bc7a880 0x100543cd8 0x1821f256c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Hi danie11am, this exception ("UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:") indicates an internal bug in UITableView.


There is a known issue where swiping to delete multiple rows quickly back-to-back can hit this exception. If you are hitting this exception without deleting multiple rows, then you're most likely hitting a different issue, and we would greatly appreciate if you can file a bug report with an attached project that reproduces it so we can investigate. Feel free to share the bug report ID in a reply here.


Thank you!

I got the same issue as the following:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:'

*** First throw call stack:

(0x181411cdc 0x180660528 0x181411bb0 0x181da0c24 0x18b33df9c 0x18b1f2aa8 0x101319ebc 0x10131a038 0x18b3531d8 0x18b359264 0x18b71d2d4 0x18b989044 0x18b988c34 0x18bd6b77c 0x18b6a4770 0x18b6a3ea8 0x18b6ade14 0x18b6b2378 0x18b1922dc 0x18b047918 0x18b69c298 0x18b69be24 0x18b69af80 0x18b045c24 0x18b01714c 0x18b96454c 0x18b966ad8 0x18b95fa6c 0x1813ba2c0 0x1813ba240 0x1813b9ac8 0x1813b76a0 0x1812d7e78 0x18316cf84 0x18b07a0bc 0x10125fd1c 0x180dfa56c)

libc++abi.dylib: terminating with uncaught exception of type NSException

We are hitting this same issue when deleting multiple rows quickly back-to-back with the swipe gesture. Would filing an additional bug report help prioritize this bug or is that not helpful in this case?

If you're hitting this issue when deleting multiple rows quickly back-to-back with the swipe gesture, you don't need to file additional bug reports. But if you encounter this exception in some other situation please do file a bug report!

Ok, here you go - bug 34871965 reported with sample project attached. Crashing 100% of the time when removing the cell using the delete button. Hope it gets fixed soon!

I would like to know this situation, is the inevitable or occasional. Because i got the crash of the outgoing version, but i used ios11 to slippery click to delete and did not reproduce. What conditions do you need? Outgoing version of the error message and you are the same

This crash issue is always reproducible using the code I shared. The conditions that I have found are:


- When running on iOS 11, no matter in simulator or device, AND

- Swipe the cell to show the delete button, then tap on delete button


The same code runs fine in iOS 10. I'm not sure what you meant by outgoing version.

Hi guys,


Does this issues fixed in iOS 11.1 and xCode 11.0.1 ? I still see this crash in my crash report console in iOS 11 for app that built via xCode 9.0.1 .

It's still crashing as far as I know. I have already raised bug report with Apple. If you raise your own separate bug report as well, it may help get attention from the Apple engineers to fix it.

tylerf,

I haven't been able to reproduce after upgrading to 11.2.

Can you please confirm if this issue is fixed in the 11.2 release?

I'm seeing crashes on 11.2 (both device and simulator) with the message "No occurance for index path (null)" when swiping to delete a single row. It happens every time, on the first attempt of swipe-to-delete. It works fine in 10.3.1 (simulator).

I'm seeing a similar assertion while moving rows in the table view. It seems to happen nearly 100% of the time when moving a table cell down below the currently-visible region (forcing the table view to scroll itself). Once it happens, the message keeps repeating in the logs every time you move the table or interact with any cell.


UITableView internal inconsistency: _visibleRows and _visibleCells must be of same length. _visibleRows: {0, 11}; _visibleCells.count: 12

2018-01-07 21:29:23.512113-0600 Testing[19019:6665452] [Assert] UITableView internal inconsistency: _visibleRows and _visibleCells must be of same length. _visibleRows: {0, 11}; _visibleCells.count: 12, _visibleCells: (
    "<Testing.ItemCell: 0x104872800; baseClass = UITableViewCell; frame = (0 72; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1d025fdd0>; layer = <CALayer: 0x1d0621b00>>",
    "<Testing.ItemCell: 0x10484dc00; baseClass = UITableViewCell; frame = (0 136; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1d025b330>; layer = <CALayer: 0x1d0420880>>",
    "<Testing.ItemCell: 0x104879400; baseClass = UITableViewCell; frame = (0 200; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1d0451cd0>; layer = <CALayer: 0x1d0422180>>",
    "<Testing.ItemCell: 0x1049a5000; baseClass = UITableViewCell; frame = (0 264; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1d04561a0>; layer = <CALayer: 0x1d04290c0>>",
    "<Testing.ItemCell: 0x1048c6400; baseClass = UITableViewCell; frame = (0 328; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1d0457b80>; layer = <CALayer: 0x1d04258c0>>",
    "<Testing.ItemCell: 0x109016e00; baseClass = UITableViewCell; frame = (0 392; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1c804a830>; layer = <CALayer: 0x1cc02f580>>",
    "<Testing.ItemCell: 0x10406d200; baseClass = UITableViewCell; frame = (0 456; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1d04419b0>; layer = <CALayer: 0x1d4232c60>>",
    "<Testing.ItemCell: 0x1048ede00; baseClass = UITableViewCell; frame = (0 520; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1d4253530>; layer = <CALayer: 0x1d0428180>>",
    "<Testing.ItemCell: 0x108012200; baseClass = UITableViewCell; frame = (0 584; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1c804f0f0>; layer = <CALayer: 0x1c802ff00>>",
    "<Testing.ItemCell: 0x108808800; baseClass = UITableViewCell; frame = (0 648; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1c40526c0>; layer = <CALayer: 0x1c403c6a0>>",
    "<Testing.ItemCell: 0x10b825400; baseClass = UITableViewCell; frame = (0 1718; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1c4051970>; layer = <CALayer: 0x1c0033260>>",
    "<Testing.ItemCell: 0x108802000; baseClass = UITableViewCell; frame = (0 712; 375 64); autoresize = W; gestureRecognizers = <NSArray: 0x1c40517f0>; layer = <CALayer: 0x1c4031fe0>>"
)


I filed a radar: 36342154

I couldn't find the radar number you had specified. Do you have any updates on this issue ?


Outcome:

I don't have an elegant solution, more of a workaround. It is mentioned below. I would still prefer a proper solution.


Scenario:

The scenario is exactly as what you described. It still seems to happen to me when a user moves a row beyond the visible cells.


Test Configuration:

iOS version: 11.2

Device and Simulator

Xcode: 9.2


Workaround:

- In controllerDidChangeContent(_:) invoke tableView.reloadData()


func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
  
    guard !isUserInitiatedMove else {
        isUserInitiatedMove = false
      
        let dispatchTime = DispatchTime.now() + 0.5
      
        DispatchQueue.main.asyncAfter(deadline: dispatchTime) {
      
            self.tableView.reloadData()
        }
      
        return
    }

    tableView.endUpdates()
}




Note: I was using NSFetchedResultsController.

Hello Conradstoll,


I am also facing the same issue with my App in UITableView. Please do let me know if you got a solution.


Thanks

Which the url of this radar?

I did not found it on openradar.

iOS 11 UITableView deleteRows crash
 
 
Q