UITableView freezes after deleting record

My MasterView application includes a table view that is populated with 10 cells containing some basic data objects such as a "header" (previously downloaded from the Internet, see next paragraph). With the Verbose Application Wizard pattern, I can use the built-in NSFetchedResultsController and its methods to handle basic data processing (such as deleting rows). When the application starts, the cells are configured with existing core data objects. At this point, I can delete the entries that I would expect.

In addition, my app also has a refresh button. When listening, it downloads some new data from the Internet and converts it into objects that are stored in the master data. The cells are configured again in the same way as before and the UITableView gets updated. Again, I can delete the entry, but now, as soon as I delete one, which then disappears normally, the table freezes (not the entire application) in the sense that its cells are no longer processable / non-responsive. I can update this too (10 records again after deleting them earlier), but the cells continue to be inaccessible. I have to stop the application to get back to normal.

On restart, one entry deleted earlier - as expected - is gone, leaving 9 entries. Again everything is working fine at the moment, I can remove a few with no problem. But once the manual update has happened, we are at the same point as before when deleting a record.

A common pattern in the absence of something specific? I'm happy to post the code, but I have no idea which parts will help ...

+3


source to share


2 answers


If an application does freeze up, deadlocks are common sources of this kind of problem . If you use dispatch_sync

anywhere, this is a common source of problems (especially with help dispatch_sync

from the main thread to what ends up doing another one dispatch_sync

back to the main thread). If you use NSLock

or @synchronized

and call them recursively, you can get stuck too.

Another source of the problem is an infinite loop (such as an error in a sentence while

that never gets executed). If you have such a loop on the main thread, it will freeze the UI. (Anything that blocks the main thread will freeze the UI.)

You may be able to diagnose where it freezes by running the application through the debugger in Xcode, and when the application freezes, press the debugger's "pause" button. While it often pauses in the middle of some rather cryptic assembly code, you can often look at the stack traces to figure out where the application was when it froze.




If you are just not updating your UI as a result of your actions, try making sure the method reloadData

is called on the main queue, if it is not, for example:

dispatch_async(dispatch_get_main_queue()) {
    self.tableView.reloadData()
}

      

+2


source


Not sure if it's related, but I ran into a freezing issue with a table view with a header and footer view that were manually reloaded after a Core Data fetch request. The table view was reloaded immediately after extraction and sometimes stopped responding to touches. Delaying tableView.reloadData () by 0.1 second fixed the problem completely.



(Without the header and footer, everything worked fine).

0


source







All Articles