diff --git a/MGSwipeTableCell/MGSwipeTableCell.m b/MGSwipeTableCell/MGSwipeTableCell.m index 0e7841b..ff4803f 100644 --- a/MGSwipeTableCell/MGSwipeTableCell.m +++ b/MGSwipeTableCell/MGSwipeTableCell.m @@ -92,14 +92,8 @@ -(instancetype) initWithButtons:(NSArray*) buttonsArray direction:(MGSwipeDirect for (UIView * button in _buttons) { if ([button isKindOfClass:[UIButton class]]) { UIButton * btn = (UIButton*)button; - - for (id target in btn.allTargets) { - if ([target isKindOfClass:self.class]) { - [btn removeTarget:target action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; //Remove all targets to avoid problems with reused buttons among many cells - } - } - - [btn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; + [btn removeTarget:nil action:@selector(mgButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; //Remove all targets to avoid problems with reused buttons among many cells + [btn addTarget:self action:@selector(mgButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; } if (!differentWidth) { button.frame = CGRectMake(0, 0, maxSize.width, maxSize.height); @@ -116,7 +110,7 @@ -(void) dealloc { for (UIView * button in _buttons) { if ([button isKindOfClass:[UIButton class]]) { - [(UIButton *)button removeTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; + [(UIButton *)button removeTarget:self action:@selector(mgButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; } } } @@ -296,7 +290,7 @@ -(BOOL) handleClick: (id) sender fromExpansion:(BOOL) fromExpansion } //button listener --(void) buttonClicked: (id) sender +-(void) mgButtonClicked: (id) sender { [self handleClick:sender fromExpansion:NO]; }