I'm trying to add swipe detection on a 2 table cells. However, so far the swipe detection only works with one table cell.
Here are parts of my code:
- (void)viewDidLoad {
[super viewDidLoad];
numbers = [[NSMutableArray alloc]init];
tableCellTrash = [[NSMutableArray alloc]init];
mSwipeRecognizer= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(removeCell:)];
[mSwipeRecognizer setDirection:( UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomPlaceCell";
CustomPlaceCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomPlaceCell" owner:nil options:nil] objectAtIndex:0];
[numbers addObject:cell];
[cell addGestureRecognizer:mSwipeRecognizer];
NSLog(@"Cell");
}
return cell;
}
-(void)removeCell:(UISwipeGestureRecognizer *)aSwipeGestureRecognizer{
NSLog(@"Swipe Detected!");
}
Anyone know why swipe detection only works for one of cells?
A
UIGestureRecognizer
can be associated only ton a single view. You should set a different gestureRecognizer for each of your cells. You may move the GestureRecognizer creation inside the