MGSwipeTableCell icon indicating copy to clipboard operation
MGSwipeTableCell copied to clipboard

Is it some ways to swipe cells programmatically ?

Open Radunani opened this issue 7 years ago • 9 comments

i just want to know if i can programmatically swipe cell at index or multiple cells, some users dont know about hidden menu there, thanks

Radunani avatar Apr 12 '17 09:04 Radunani

I have the exact same question... any luck with it?

ghost avatar May 03 '17 13:05 ghost

i did not find any solution and just did in other way..

Radunani avatar May 03 '17 14:05 Radunani

@Radunani Share it 👍

mrhaxic avatar May 03 '17 15:05 mrhaxic

in my case i just add a button in each cell when is in edit mode, and that button have the same action like my second button in swipe, i find a solution just to show to user he can swipe it

you can try it in did select or when tableview going to edit mode

// UITableViewCell *cell = [_customWorkoutsTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

//

// __block UILabel *swipeLabel = [[UILabel alloc]initWithFrame:CGRectMake(cell.bounds.size.width,

// 0,

// 200,

// cell.bounds.size.height)];

//

// swipeLabel.text = @" Swipe Me";

// swipeLabel.backgroundColor = [UIColor greenColor];

// swipeLabel.textColor = [UIColor blackColor];

// [cell addSubview:swipeLabel];

//

// [UIView animateWithDuration:0.3 animations:^{

// [cell setFrame:CGRectMake(cell.frame.origin.x - 100, cell.frame.origin.y, cell.bounds.size.width, cell.bounds.size.height)];

// } completion:^(BOOL finished) {

// [UIView animateWithDuration:0.3 animations:^{

// [cell setFrame:CGRectMake(cell.frame.origin.x + 100, cell.frame.origin.y, cell.bounds.size.width, cell.bounds.size.height)];

// } completion:^(BOOL finished) {

// [swipeLabel removeFromSuperview];

// swipeLabel = nil;

// }];

Radunani avatar May 04 '17 07:05 Radunani

Check this methods, you can use them to swipe programmatically, show hints, etc:

/** Utility methods to show or hide swipe buttons programmatically */
-(void) hideSwipeAnimated: (BOOL) animated;
-(void) hideSwipeAnimated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated;
-(void) showSwipe: (MGSwipeDirection) direction animated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animated: (BOOL) animated completion:(nullable void(^)(BOOL finished)) completion;
-(void) setSwipeOffset:(CGFloat)offset animation: (nullable MGSwipeAnimation *) animation completion:(nullable void(^)(BOOL finished)) completion;
-(void) expandSwipe: (MGSwipeDirection) direction animated: (BOOL) animated;

MortimerGoro avatar May 13 '17 10:05 MortimerGoro

Sure, you can do that. This was my main reason for switching from the default iOS implementation to MGSwipeTableCell.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    MGSwipeTableCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if(cell) {
        [cell showSwipe:MGSwipeDirectionRightToLeft animated:YES];
    }
}

Hope that helps!

iiAtlas avatar Oct 31 '17 16:10 iiAtlas

Swift example:

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath) as! MGSwipeTableCell
        cell.showSwipe(.rightToLeft, animated: true)
    }

ezefranca avatar Dec 22 '17 15:12 ezefranca

Make sure you set the delegate of the cell or else it won't trigger

russelltwarwick avatar Jun 18 '18 14:06 russelltwarwick

Here is one way, by updating table view for the specific cell: self.tableView.reloadRows(at: [indexPath], with: .right)

AminPlusPlus avatar Aug 16 '20 05:08 AminPlusPlus