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

Is it some ways to swipe cells programmatically ? #275

Open Radunani opened 7 years ago

Radunani commented 7 years ago

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

ghost commented 7 years ago

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

Radunani commented 7 years ago

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

mrhaxic commented 7 years ago

@Radunani Share it 👍

Radunani commented 7 years ago

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;

// }];

MortimerGoro commented 7 years ago

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

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!

ezefranca commented 6 years ago

Swift example:

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

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

AminPlusPlus commented 4 years ago

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