Skip to content

Commit

Permalink
Added the "refreshButtons" utility method to dynamically change left …
Browse files Browse the repository at this point in the history
…of right buttons
  • Loading branch information
MortimerGoro committed Oct 26, 2014
1 parent cbd3aad commit 117a491
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions MGSwipeTableCell/MGSwipeTableCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ typedef NS_ENUM(NSInteger, MGSwipeState) {

/** Refresh method to be used when you want to update the cell contents while the user is swipping */
-(void) refreshContentView;
/** Refresh method to be used when you want to dinamically change the left or right buttons (add or remove)
* If you only want to change the title or the backgroundColor of a button you can change it's properties (get the button instance from leftButtons or rightButtons arrays)
* @param usingDelegate if YES new buttons will be fetched using the MGSwipeTableCellDelegate. Otherwise new buttons will be fetched from leftButtons/rightButtons properties.
*/
-(void) refreshButtons: (BOOL) usingDelegate;

@end

20 changes: 19 additions & 1 deletion MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,26 @@ -(void) refreshContentView
BOOL prevValue = _triggerStateChanges;
_triggerStateChanges = NO;
self.swipeOffset = 0;
_triggerStateChanges = prevValue;
self.swipeOffset = currentOffset;
_triggerStateChanges = prevValue;
}

-(void) refreshButtons: (BOOL) usingDelegate
{
if (usingDelegate) {
self.leftButtons = @[];
self.rightButtons = @[];
}
if (leftView) {
[leftView removeFromSuperview];
leftView = nil;
}
if (rightView) {
[rightView removeFromSuperview];
rightView = nil;
}
[self createSwipeViewIfNeeded];
[self refreshContentView];
}

#pragma mark Handle Table Events
Expand Down

0 comments on commit 117a491

Please sign in to comment.