Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i swipe on a table cell and make it call a function?

How can i swipe my finger on a table cell and call a function ( in which i push a view controller to my navigation controller ) ?

like image 561
Alex Avatar asked Feb 23 '23 15:02

Alex


1 Answers

Just add a UISwipeGestureRecognizer to the cell.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    UISwipeGestureRecognizer *g = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellWasSwiped:)];
    [cell addGestureRecognizer:g];
    [g release];
}

Then implement the method to handle the swipe:

- (void)cellWasSwiped:(UIGestureRecognizer *)g {
    NSLog(@"Swiped");
}
like image 167
Morten Fast Avatar answered May 20 '23 08:05

Morten Fast