MortimerGoro / MGSwipeTableCell

An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.
MIT License
6.96k stars 1.07k forks source link

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

Open KhaVNguyen opened 8 years ago

KhaVNguyen commented 8 years ago

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.

FloLecoeuche commented 8 years ago

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.

MortimerGoro commented 8 years ago
  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;