MGSwipeTableCell icon indicating copy to clipboard operation
MGSwipeTableCell copied to clipboard

How to call a method when a swipe has begun or prevent unswipe when tableView.reloadData()?

Open KhaVNguyen opened this issue 9 years ago • 2 comments

I have a process in the background that modifies realm, which causes the table view to constantly reload data when it is running. The problem with this is that as the table view is constantly reloaded, the MGSwipeTableViewCells in my table view are also reloaded and are forced to the unswiped position.

Is there a way either:

  1. Prevent the MGSwipeTableViewCells from unswiping upon calling tableView.reloadData()
  2. Access the method called when the swipe gesture is began in order to temporarily pause my background process and subsequently stop calling tableView.reloadData() while a swipe action is being done.

Thanks for the help.

KhaVNguyen avatar Aug 08 '16 17:08 KhaVNguyen

I had the same issue. Use insertRowsAtIndexPaths, reloadRowsAtIndexPaths, deleteRowsAtIndexPaths instead reloadData and before reloadRowsAtIndexPaths check the swipeOffset of the current MGSwipeTableCell; if it's true the swipe is activated so don't reload that cell for keep the swipe. I hope this answer help you.

FloLecoeuche avatar Aug 17 '16 12:08 FloLecoeuche

  1. Prevent the MGSwipeTableViewCells from unswiping upon calling tableView.reloadData()

You could save the swipeOffset of each visible cell and restore the values after calling reloadData.

  1. Access the method called when the swipe gesture is began in order to temporarily pause my background process and subsequently stop calling tableView.reloadData() while a swipe action is being done.

You can use this delegate methods:

-(void) swipeTableCellWillBeginSwiping:(MGSwipeTableCell ) cell; -(void) swipeTableCellWillEndSwiping:(MGSwipeTableCell *) cell; -(void) swipeTableCell:(MGSwipeTableCell) cell didChangeSwipeState:(MGSwipeState) state gestureIsActive:(BOOL) gestureIsActive;

MortimerGoro avatar Aug 24 '16 15:08 MortimerGoro