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