UITableView need long press to select a row
Asked Answered
R

4

9

Anyone has ever come into the problem that UITableView need long press to trigger the didSelectRowAtIndexPath method?

Rasp answered 14/11, 2013 at 6:9 Comment(2)
@iPatel Thank you for the instant answer, it works~Rasp
@keywind: accept iPatel's answer if it solves your problemIndophenol
E
24

If you have used any gesture recognizer try to removing it and check if it causing the problem or not ?

Other wise

Not sure but The problem might be in the UITableView has delaysContentTouches turned ON. Turn this OFF so touches get through to the cells faster.

Eonism answered 14/11, 2013 at 6:21 Comment(0)
H
4

In my situation I had a UITapGestureRecognizer on my view for hiding my keyboard.

This solved the problem:

tap.cancelsTouchesInView = false
Hapsburg answered 11/6, 2016 at 16:6 Comment(0)
C
2

I had exactly the same trouble :

  • I used the Tap Gesture recognizer to manage different action in my View Controller
  • I wanted a classic tap (short click) to trigger the didSelectRowAtIndexPath method but just a long press working by default

My solution to select a cell in Table View by a short tap (press) :

  • Select your Tap Gesture recognizer in your Story Board
  • Go to the attributes inspector and deselect "Canceled in view"
Coleorhiza answered 20/3, 2014 at 13:18 Comment(1)
This was my problem as well. The flag is called "cancelsTouchesInView" which kind of makes sense.Cornwallis
B
0

You have to add UILongPressGesture to your cell's view and on fire just call didSelectRowAtIndexPath (better will be to call another method - not standard UITableViewDelegate's method) from your class that adopts UITableViewDelegate.

I will suggest You create own protocol, inherited from UITableViewDelegate, add there method for long press behavior method and enjoy. Something similar to:

@protocol LongPressTableViewCellDelegate <UITableViewDelegate>
- (void)tableView:(UITableView *)tableView didLongTapCell:(UITableViewCell *)cell;
@end

Your delegate in this case would adopt not standard UITableViewDelegate, but this one. Also You have to create own cell (inherited from UITableViewCell) and add there delegate property (id ) that will be used when long press fired.

Also there can be situation that standard didSelectRowAtIndexPath will be fired before your long press will fire, so I suggest you to disable standard selection behavior for table view:

_tableView.allowsSelection = NO;
Broke answered 14/11, 2013 at 6:19 Comment(1)
He does not want the long press, he tries to get rid of itHendiadys

© 2022 - 2024 — McMap. All rights reserved.