Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView need long press to select a row

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

like image 582
keywind Avatar asked Nov 14 '13 06:11

keywind


People also ask

What is a UITableView?

UITableView manages the basic appearance of the table, but your app provides the cells ( UITableViewCell objects) that display the actual content. The standard cell configurations display a simple combination of text and images, but you can define custom cells that display any content you want.

How do you make a tableView cell Unselectable?

To completely prevent selection of the UITableViewCell , have your UITableViewDelegate implement tableView:willSelectRowAtIndexPath: . From that method you can return nil if you do not want the row to be selected. This prevents the row from being selected and tableView:didSelectRowAtIndexPath: from being called.


3 Answers

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.

like image 182
iPatel Avatar answered Sep 21 '22 16:09

iPatel


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

This solved the problem:

tap.cancelsTouchesInView = false
like image 38
Dan Beaulieu Avatar answered Sep 18 '22 16:09

Dan Beaulieu


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"
like image 45
GéraldT Avatar answered Sep 19 '22 16:09

GéraldT