My Existing TableViewController is crashing on Xcode 11 beta1
I have faced the same issue when providing support for iOS 13.
This is a new exception in iOS 13 that
UITableView
will raise in order to prevent and proactively alert you of a situation that would previously cause undefined behaviour and a variety of strange, seemingly unrelated, and hard-to-debug issues (including crashes).What is happening here is that
UITableView
is in the middle of asking its dataSource to return a cell for eachvisible row
and is configuring the properties of the returned cells so they can be displayed. And in the middle of this updating -- most likely inside a callback from the table view itself about a specific row such astableView(_:cellForRowAt:) tableView(_:canEditRowAt:)
, etc -- your code is asking the table view to return the visible cells. This is obviously problematic, becauseUITableView
is right in the middle of preparing those cells, so it cannot possibly return a meaningful answer.The fix for this is to look at where you are calling
visibleCells
in the backtrace when thisexception
is raised, and then do one of two things:
Option 1:
Move the usage of
visibleCells
to a better place, so that you aren't asking for thevisibleCells
from someplace that is called during the process of creating/configuring/updating those same cells. A great place to ask for the visible cells is after the table view lays out, so for example if the table view is the view of a view controller you can useviewDidLayoutSubviews
(), or in a subclass ofUITableView
do it after callingsuper.layoutSubviews()
.
Option 2:
Depending on what you're actually trying to do, you might be able to skip using visible cells altogether. For example, you might be able to leverage the callbacks
tableView(_:willDisplay:forRowAt:)
andtableView(_:didEndDisplaying:forRowAt:)
to track when cells are visible instead.If you are hitting this exception and you think you are requesting the visible cells from a location that should be valid/allowed, please share the backtrace when you hit this exception and details about what you're trying to do.
Update:
I am sure but plateNoPrefix.becomeFirstResponder()
causing the crash. As of now, you can check by pasting this code in viewDidAppear
method
OR
Execute this code after delay (Worked for me)
DispatchQueue.main.asyncAfter(deadline: .now()+0.1) {
// Your code
}
For details clerification you can refer Apple Developer Forum
This is a new exception in iOS 13 that UITableView will raise in order to prevent and proactively alert you of a situation that would previously cause undefined behavior and a variety of strange, seemingly unrelated, and hard-to-debug issues
Please have a look at Apple Developer Forum