iOS 11 [Assert] UITableView internal inconsistency:

Just came across an interesting error message. In iOS11 my tableview is going crazy when refreshing. I have not seen this before nor can I find anything to assist me in finding the bug causing it.


Can anyone point me in the right direction? Thanks.


[Assert] UITableView internal inconsistency: _visibleRows and _visibleCells must be of same length. _visibleRows: {0, 13}; _visibleCells.count: 16, _visibleCells: (
    "<UITableViewCell: 0x7fc2450ec400; frame = (0 0; 375 5); text = ''; autoresize = W; layer = <CALayer: 0x604001c34620>>",
    "<NMCarouselCell: 0x7fc23f8cda00; baseClass = UITableViewCell; frame = (0 5; 375 155); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x6000030249e0>>",
    "<UITableViewCell: 0x7fc245024a00; frame = (0 160; 375 5); text = ''; autoresize = W; layer = <CALayer: 0x60400103cb40>>",
    "<NMPostTitleAvatarComponentCell: 0x7fc23f3c6c00; baseClass = UITableViewCell; frame = (0 165; 375 62); clipsToBounds = YES; autoresize = W; gestureRecognizers = <NSArray: 0x60000264e7f0>; layer = <CALayer: 0x600002c28a20>>",
    "<NMMessageComponentCell: 0x7fc23fb38800; baseClass = UITableViewCell; frame = (0 227; 375 36.112); autoresize = W; gestureRecognizers = <NSArray: 0x600002443db0>; layer = <CALayer: 0x6000016362c0>>",
    "<NMPostCategoryComponentCell: 0x7fc23f90ac00; baseClass = UITableViewCell; frame = (0 263.112; 375 26); autoresize = W; gestureRecognizers = <NSArray: 0x600002a438a0>; layer = <CALayer: 0x600001a22aa0>>",
    "<NMThanksReplyComponentCell: 0x7fc23f9ba800; baseClass = UITableViewCell; frame = (0 289.112; 375 44); autoresize = W; gestureRecognizers = <NSArray: 0x6000020525d0>; layer = <CALayer: 0x600000c31580>>",
    "<UITableViewCell: 0x7fc23f90b200; frame = (0 333.112; 375 5); text = ''; autoresize = W; layer = <CALayer: 0x600002025ec0>>",
    "<NMHeaderComponentCell: 0x7fc23ff29e00; baseClass = UITableViewCell; frame = (0 338.112; 375 22); clipsToBounds = YES; autoresize = W; gestureRecognizers = <NSArray: 0x600001e421c0>; layer = <CALayer: 0x6000028280c0>>",
    "<NMPostTitleAvatarComponentCell: 0x7fc23f164800; baseClass = UITableViewCell; frame = (0 360.112; 375 62); clipsToBounds = YES; autoresize = W; gestureRecognizers = <NSArray: 0x60000245e420>; layer = <CALayer: 0x6000014305a0>>",
    "<NMMessageComponentCell: 0x7fc23e06ca00; baseClass = UITableViewCell; frame = (0 422.112; 375 55); autoresize = W; gestureRecognizers = <NSArray: 0x60400145c410>; layer = <CALayer: 0x604001825fc0>>",
    "<NMButtonComponentCell: 0x7fc2450e9000; baseClass = UITableViewCell; frame = (0 477.112; 375 56); autoresize = W; layer = <CALayer: 0x604000a2e4e0>>",
    "<NMImageAttachmentsComponentCell: 0x7fc23f8f5800; baseClass = UITableViewCell; frame = (0 533.112; 375 165); autoresize = W; gestureRecognizers = <NSArray: 0x600001651970>; layer = <CALayer: 0x6000014233e0>>",
    "<NMMessageComponentCell: 0x7fc245113c00; baseClass = UITableViewCell; frame = (0 422.112; 375 55); autoresize = W; gestureRecognizers = <NSArray: 0x604001847800>; layer = <CALayer: 0x604001a33fe0>>",
    "<NMButtonComponentCell: 0x7fc2450e9000; baseClass = UITableViewCell; frame = (0 477.112; 375 56); autoresize = W; layer = <CALayer: 0x604000a2e4e0>>",
    "<NMImageAttachmentsComponentCell: 0x7fc23f8f5800; baseClass = UITableViewCell; frame = (0 533.112; 375 165); autoresize = W; gestureRecognizers = <NSArray: 0x600001651970>; layer = <CALayer: 0x6000014233e0>>"
)

What do you mean by refreshing? Are you using beginUpdates/endUpdates?

Hello Micheal,


Did you find a solution for this? I am facing the same issue with my App.

I have the same question when call these method "beginUpdates()" and "endUpdates()".

There is a UITextView instance as the subview of UITableViewCell. When the content of UITextView instance did change, I call the method "contentDidChange" as following:

- (void)contentDidChange:(TTAboutMeCell *)aboutMeCell {
  [self.tableView beginUpdates];
  [self.tableView endUpdates];
}

iOS version is 11.1.1; BUT, on iOS 11.2.6, this code works well.

This seems odd, beginUpdates “Begins a series of method calls that insert, delete, or select rows and sections of the table view” and you have no such method calls.

This assert indicates that the UITableView internal state is "corrupted". The most frequent cause is when the table view is performing an update or reload, and is in the middle of a callback to one of the data source or delegate methods, and somehow your code causes unexpected "reentrancy" on the UITableView (e.g. by performing another update/reload or by manually running the main runloop) from inside this callback. This causes UITableView to get into an inconsistent internal state because it's already in the middle of processing another update.


If you can reproduce this in a standalone sample project, please file a bug report at https://bugreport.apple.com and attach your sample project.

@FrameworksEngineer I filed FB8768071. In my case I have a bad interaction between UITableView and the NSAttributedString() init method that converts html to an attributedString. It was being called while updating a tableViewCell and this caused cellForRowAt to be called again while my app code was already processing a cellForRowAt call. And the tableView lost its mind after that.
iOS 11 [Assert] UITableView internal inconsistency:
 
 
Q