Detect when UITableView is reordering

I have a UITableView supported by NSFetchedResultsController that can trigger updates at any time. If the user is currently reordering rows, applying these updates will throw an exception because the table view is temporarily captured and you get an error message like

Invalid update: invalid number of rows in section [...]

How can I determine when a user started moving a cell so that I can delay updates caused by the selected result controller? Apparently, there are no methods for delegating table views to detect this. This delegate method:

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {

It is not called when the user first separates the first cell, only when they really move it somewhere else.

One solution is to check the isEditingreturned results in the queries and just in bulk reloadDatainstead of dynamically inserting / deleting rows, but I wonder if there is a way to specifically check the "reordering" mode.

+3
source share
2 answers

You are mistaken, tableView: canMoveRowAtIndexPath does not solve the problem.

Use [cell setEditing: NO] for all the cells that you want to update or delete.

If the user dragged the cell, the drag mode will be canceled.

If you need [cell setEditing: YES], you can restore it immediately after completing what you are updating.

+1
source

Before the table moves the row it sends ...

tableView:canMoveRowAtIndexPath:

... . , , .

, . , , . , - concurrency , . , , .

0

Source: https://habr.com/ru/post/1742970/


All Articles