Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Existing TableViewController is crashing on Xcode 11 beta1

I have developed a UITableViewController screen. It's working fine on Xcode 10.2 but. When I run on Xcode 11 beta 1 it's crashing like below.

I didn't find what was happening.

In ViewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.tableFooterView = UIView()
    plateNoPrefix.becomeFirstResponder() // static cell textfield in tableViewcell
}

Exception… Attempted to access the table view's visibleCells while they were in the process of being updated, which is not allowed

like image 591
Kathiresan Murugan Avatar asked Jun 19 '19 07:06

Kathiresan Murugan


2 Answers

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 each visible 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 as tableView(_:cellForRowAt:) tableView(_:canEditRowAt:), etc -- your code is asking the table view to return the visible cells. This is obviously problematic, because UITableView 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 this exception 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 the visibleCells 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 use viewDidLayoutSubviews(), or in a subclass of UITableView do it after calling super.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:) and tableView(_: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

like image 78
Hitesh Surani Avatar answered Oct 19 '22 20:10

Hitesh Surani


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

like image 45
Vinu David Jose Avatar answered Oct 19 '22 18:10

Vinu David Jose