Reloading scoreboards and touch gestures

I have a table view that reloads as new content is added using [tableview reloadData];

The problem is that I have a UILongPressGestureRecognizer in the TableCells in the table, and since apples / table often reloads, LongPress does not always work, I assume that the internal timers constitute reset when the cell / table reloads.

+6
source share
3 answers

Have you tried to see the state of your UILongPressGestureRecognizer before [tableView reloadData] ? For instance:

 // Returns |YES| if a gesture recognizer began detecting a long tap gesture - (BOOL)longTapPossible { BOOL possible = NO; UIGestureRecognizer *gestureRecognizer = nil; NSArray *visibleIndexPaths = [tableView indexPathsForVisibleRows]; for (NSIndexPath *indexPath in visibleIndexPaths) { // I suppose you have only one UILongPressGestureRecognizer per cell gestureRecognizer = [[tableView cellForRowAtIndexPath:indexPath] gestureRecognizers] lastObject]; possible = (gestureRecognizer.state == UIGestureRecognizerStateBegan || gestureRecognizer.state == UIGestureRecognizerStateChanged); if (possible) { break; } } return possible; } // ... later, where you reload the tableView: if ([self longTapPossible] == NO) { [tableView reloadData]; } 

Let me know if this works!

+4
source

Do not use reloadData if you want existing cells to remain. Instead, when you get new data, use the Insert and Delete Cells methods to inform the table view about which cells have changed. General procedure:

  • You get new data.
  • Call beginUpdates
  • Call deleteRowsAtIndexPaths:withRowAnimation: to remove cells for any old items that were deleted in the new data.
  • Call insertRowsAtIndexPaths:withRowAnimation: to add new cells for any items that have been added to the new data.
  • If you need to selectively replace a specific cell for any reason (and cannot just update existing sub-categories of cells with new data), use reloadRowsAtIndexPaths:withRowAnimation:
  • Call commitUpdates . At the moment, your UITableViewDataSource methods should reflect the new data (for example, tableView:numberOfRowsInSection: should reflect the changed counter, and tableView:cellForRowAtIndexPath: should use the new elements).
  • Now the table view will call your data source methods needed to update the display. Existing rows will not be changed.
+3
source

Set BOOL as aCellIsSelected to YES when you touch a cell

and just reload the table if aCellIsSelected NO

0
source

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


All Articles