Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a possibility to disable/enable swipe actions of the cell #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add a possibility to disable/enable swipe actions of the cell #275

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 6, 2015

I have a business logic in the app where I should enable/disable swipe actions for one particular cell.
Initially I implement it by adding and removing buttons to the cell itself. But there was one issue with this solution. When user make pan gesture on the scroll view of the cell without buttons it changes content offset of a scrollview on every deceleration event and user see nothing. If table reload all cells in time when cell still have decelerating scroll view and still receiving deceleration events and such cell received some new buttons then correction logic implemented in deceleration event delegate method not work any more. Scroll view changes it's offset on next deceleration event and user see "randomly" cell that swiping by itself.

I think that it could always good to have a switch to enable/disable swipe actions without a side effects.

@bishalg
Copy link

bishalg commented Aug 6, 2015

is this related to #87

@ghost
Copy link
Author

ghost commented Aug 6, 2015

No, this is about reuse logic and life cycle of the UITableViewCell. Imagine that cell behaviour on the swipe is based on one boolean property. In the method - (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state{ cell checks this property to determinate if it should do swipe.
In the lifecycle we have two major points there - before and after reuse. Implementation of this method (canSwipeToState) is based on UIScrollViewDelegate method call. It is called each time scroll view makes decision to scroll.
Think about particular instance of the cell now. User try to swipe this cell. it's boolean property was set to NO and on each deceleration event it call the delegate method and correct offset of the UIScorllView. Imagine the cell was reused. Right after reuse property of this cell was set to YES, but the deceleration still effects on the scroll view. The cell calls it's delegate method and now it return YES, it could scroll. Please point attention that cell now represent different amount of data. So user see that randomly cells swipes out right after appearing on the screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant