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

Subclassed Cell - No interaction with tappedButtonAtIndex #259

Closed shawn458 closed 7 years ago

shawn458 commented 7 years ago

I have subclassed the cell and I am trying the retrieve the index path of the tapped cell but I receive no interaction. Can anyone please help?

I have called the Delegate:

#import "ContactsMGCell.h"

@interface ContactsTableViewController : UITableViewController <MGSwipeTableCellDelegate>

@end

The cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    ContactsMGCell *cell = (ContactsMGCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[ContactsMGCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.delegate = self;

    PFObject *object = [self.contacts objectAtIndex:indexPath.row];
    if (object) {
        cell.title.text = [NSString stringWithFormat:@"%@ %@", [object objectForKey:@"firstName"], [object objectForKey:@"lastName"]];
    }

    cell.rightButtons = @[[MGSwipeButton buttonWithTitle:@"Cancel" backgroundColor:[UIColor colorWithRed:204.0/255.0 green:34.0/255.0 blue:41.0/255.0 alpha:1.0]]];    
    cell.rightSwipeSettings.transition = MGSwipeTransitionBorder;

    return cell;
}

The tappedButtonAtIndex

- (BOOL)swipeTableCell:(PendingRequestsMGCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion {
    NSLog(@"Cell: %ld", [self.tableView indexPathForCell:cell].row);

    return YES;
}
shawn458 commented 7 years ago

Closing this as I was able to resolve the issue.

thaoth58 commented 7 years ago

hello, could you tell me how you do this? Thank in advance :D

shawn458 commented 7 years ago

No problem.

For the tappedButtonAtIndex, I just needed to change the PendingRequestsMGCell to ContactsMGCell (the custom cell that I imported). A really minor mistake that was overlooked.

- (BOOL)swipeTableCell:(ContactsMGCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion {
    NSLog(@"Cell: %ld", [self.tableView indexPathForCell:cell].row);

    return YES;
}

Let me know if you have a specific question.