1) Add a UILongPressGestureRecognizer
to you cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//add longPressGestureRecognizer to your cell
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
//how long the press is for in seconds
lpgr.minimumPressDuration = 1.0; //seconds
[cell addGestureRecognizer:lpgr];
}
return cell;
}
2) Handle the longPress and push to you editViewController
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if (indexPath == nil) {
NSLog(@"long press on table view but not on a row");
}
else
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
NSLog(@"long press on table view at row %ld", (long)indexPath.row);
editViewController *editView = [self.storyboard instantiateViewControllerWithIdentifier:@"editView"]; //dont forget to set storyboard ID of you editViewController in storyboard
[self.navigationController pushViewController:editView animated:YES];
}
}
}
3) Normal press push to your DetailsViewController
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailsViewController *detailView = [self.storyboard instantiateViewControllerWithIdentifier:@"detailView"]; //dont forget to set storyboard ID of you editViewController in storyboard
[self.navigationController pushViewController:detailView animated:YES];
}
solved Long touch (touch and wait) on the cells in tableView