alikaragoz/MCSwipeTableViewCell

I think it's cancelling UITapGestureRecognizer inside my cell subclass

benhowdle89 opened this issue · 7 comments

Just looking to eliminate this from debugging, would it be a possibility that the library is conflicting with existing Gesture Recognizers I have set up inside my cell?

I'm not aware of gesture recognizer conflicts but we are not immune to bugs. Do you have more information to share, I will look into it.
Thanks.

Thanks @alikaragoz, really appreciated.

So, in my custom table view cell subclass:

// .h file
#import <MCSwipeTableViewCell/MCSwipeTableViewCell.h>

@interface PLOTCheckinTableViewCell : MCSwipeTableViewCell
@property(nonatomic, strong) NSDictionary *item;
@property(nonatomic, strong) UIImageView *poster;
- (void)setDidTapMovieTitleBlock:(void (^)(id sender))didTapMovieTitleBlock;
@end

// .m file
@interface PLOTCheckinTableViewCell ()
@property (copy, nonatomic) void (^didTapMovieTitleBlock)(id sender);
@end

// adding the content within a method (self.metaView is a UIView added to self.contentView)
self.movieTitle = [[UILabel alloc] initWithFrame:CGRectMake(85, 15.5, self.contentView.bounds.size.width - 85 - 50 - 20, 26)];
self.movieTitle.userInteractionEnabled = YES;
UITapGestureRecognizer *tapOnMovieTitle = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedMovieTitle:)];
tapOnMovieTitle.delegate = self;
[self.movieTitle addGestureRecognizer:tapOnMovieTitle];
[self.metaView addSubview:self.movieTitle];

- (void)tappedMovieTitle:(id)sender {
    if (self.didTapMovieTitleBlock) {
        self.didTapMovieTitleBlock(sender);
    }
}

Then in the View Controller:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PLOTCheckinTableViewCell *cell = (PLOTCheckinTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CheckinCellIdentifier forIndexPath:indexPath];
    NSDictionary *checkin = self.items[indexPath.row];
    cell.item = checkin;
    [cell setDidTapMovieTitleBlock:^(id sender) {
       // never comes in here now
    }];
    return cell;
}

If I put a breakpoint inside tappedMovieTitle, it never comes into the method when tapped. The swipe functionality works perfectly aside from this, however I'm only thinking the two are linked because if I subclass UITableViewCell again, the Gesture Recogniser works a-ok!

I'm hoping it's something silly I've done and not a bug in your library, because apart from this, it's been ace and so easy to integrate!

Hi @benhowdle89 thanks for all the details.

It seems that there is actually a bug in the library... The fix is easy, I will soon do a commit.

In the mean time there is an easy workaround for you. In the code of your custom cell you can implement the delegate of your UIGestureRecognizer:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {

    // If the gesture recognizer is yours.
    if (gestureRecognizer == self.tapOnMovieTitle) {
        return YES;
    }  

    // For other gesture recognizers rely on super.
    return [super gestureRecognizerShouldBegin:gestureRecognizer];
}

Please let me know if that works for you.

Oh ace, thanks a bunch, will give this a go. I'm relatively new to iOS (more web), and I did have a look through the lib code, but I couldn't see anything obvious in there that could be wrong, so I'll be really curious to see which bit(s) were the issue!

Your are welcome! You can check commit eb0717e to see the fix. Nothing really exciting :)
Thank you for the report 👍

Hey man, not sure if this is linked, but this now breaks UITableview scrolling & pull to refresh (UIRefreshControl) 😞

Not my call at all, but would it be better to actually just document the workaround you gave me as the actual approach to do, as opposed to the return YES; in your lib?

Wow, I don't know how I miss that... I will rollback my changes. I will indeed document it instead.
Thanks again for your help on this.