UITableView dataSource is not set (17.4.1 (21E236) only)

#0 Thread
NSInternalInconsistencyException
UITableView dataSource is not set
0
CoreFoundation
___exceptionPreprocess + 164

20
UIKitCore
___swift_destroy_boxed_opaque_existential_1Tm + 12004

There is very little information about the call to the stack.

Some of our iOS App users are suddenly experiencing a ** "UITableView dataSource is not set"** crash.

I don't think it's a coincidence that these users are all 17.4.1 users.

This exception would be thrown if UITableView's dataSource is unexpectedly nil while trying to update itself, such as while preparing a cell. What is your UITableView data source expected to be? Keep in mind that UITableView's delegate is weak, so it's possible for it to deallocate if you're not strongly retaining it yourself (meaning you may be relying on a memory race that can change across iOS updates).

We're facing the same crash in our iOS app. Interestingly, we set the tableView's dataSource to self in a view controller class in the method in which the crash is reported - so it's very weird seeing that it is nil.

We have:

if tableView.dataSource == nil {
    tableView.dataSource = self
    /* some other logic */ 
}
tableView.reloadData()
tableView.layoutIfNeeded()

There is a catch, however: after this code, we need to wait for one run loop cycle using DispatchQueue.main.async, for the layout to complete (hence layoutIfNeeded call), after which scrollToRow is attempted.

In DispatchQueue.main.async's closure, table view is weakly captured, so it should be non-nil if the view controller is non-nil, as nothing else is retaining it.

Memory of every instance in this view controller is carefully managed. Once the view controller gets removed from its navigation controller, everything goes out of memory; no retain cycles, no work being performed after the controller is deallocated. Combine is used for async tasks and every task gets cancelled once the view controller is deinitialized.

There may be a mistake in our code that we haven't found yet, but I'm reporting this since I'm seeing we're not the only one with the issue.

The crash so far occurred only on iOS 17.5.1

UITableView dataSource is not set (17.4.1 (21E236) only)
 
 
Q