16

My app uses a UITableView with a UINavigationController to show a more detailed view when a row of the table is tapped - the basic drill-down routine.

When I tap on a row, it is highlighted, but the delegate methods tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath: are not called (verified using debugger).

Now here's the weird part:

  1. There are some other table views in the app (they don't drill down) and none of them exhibit the issue.

  2. If I tap the row rapidly and repeatedly, after many tries (10 - 20 is normal), tableView:willSelectRowAtIndexPath: and tableView:didSelectRowAtIndexPath: are called and processing continues normally.

  3. The problem occurs only on an (any, actually) iPad running iOS 6. It works fine with iPads running iOS 5, or with any iPhone running any iOS version, 6. It also works with the iPad simulator using iOS 5 or 6.

So it seems that something is receiving the tap before the delegate methods are called. But what?

I not using any UITapGestureRecognizer, so that is not the issue. I am not using multiple UITableViewControllers for the table, so this is also not the issue.

9
  • 1
    Check these things: 1. Confirm the you are the delegate. 2. Does the cells contain any other view? Possibly a UIScrollView or any of it's descendants? 3. Are you running anything very demanding on the main thread?
    – ABeanSits
    Sep 26, 2012 at 21:02
  • 1. Yes, I am definitely the delegate. 2. Some of the cells contain a UIImageView (with user interaction disabled), the rest contain just the usual UILabel. 3. No, the app is idling. Sep 26, 2012 at 21:09
  • Have you done any kind of override of the main UIWindow?
    – Mike M
    Sep 26, 2012 at 21:26
  • Have you set a window rootViewController correctly? iOS6 causes a few things to break if you haven't done this.
    – Roger
    Sep 26, 2012 at 21:45
  • @Mike M I did not override the main UIWindow in any way. Sep 26, 2012 at 22:49

9 Answers 9

11

I was having this issue with an app when running in iOS6. The tableView:didSelectRowAtIndexPath: method was never being triggered, even though it was working before updating to iOS6.

I finally figured it out by looking at the xib and the attribute inspector for the table. In the Table View section I had the Selection option set to No Selection and Show Selection on Touch was not selected.

Changing the Selection option to Single Selection actually got this working for me again and leaving the Show Selection on Touch unselected means that I don't see any flash or change of colour when the row is selected.

3
  • I checked my storyboard file. The Selection is set to Single Selection. Show Selection on Touch does not seem to have any effect. Oct 28, 2012 at 13:17
  • I am not using a storyboard, so maybe this is why it is different for me. Sorry I can't be more helpful. Oct 29, 2012 at 20:12
  • 1
    Yes, It's a correct answer on IOS 6 and 7, if you set table to no selection, "DidSelectRowAtIndexPath" will not be called. I have tested it and it works like that. Jun 27, 2014 at 10:16
8

I encountered a similar issue. iOS 6 appears to be much more sensitive to the slightest upward movement on a tap on a table view cell. It appears it is registering the slightest movement as a scroll request rather than a cell selection. My table view was set to scrollEnabled = NO because it is a table view with static selection values. The table view appears within a small area of a larger iPad view. If I carefully tap a cell and lift directly up, the cell is selected.

To resolve it, I changed scrollEnabled to YES and made sure the area dedicated to my tableView was larger than the actual area needed to show the table view, thus preventing it from scrolling. Not sure if this is is the cause of the issue you are experiencing, but hope it helps.

2
  • Interesting. scrollEnabled is YES for the UITableView, because it can get larger than the screen, so that is not it. But your indication that iOS 6 is more sensitive to movement while tapping is something I will definitely investigate! I'm under the impression that it has become a lot harder to perform certain taps in other applications (mostly games) as well, so maybe this is something that Apple must fix (not that they acknowledge there is an issue ... sigh ;). Oct 1, 2012 at 18:41
  • Thanks! That was my problem as well. Really weird behavior. If you have a ScrollView that should not bounce you could use self.tableView.bounces = NO;.
    – thijsai
    Aug 11, 2014 at 10:12
6

I had the same problem. The UITableView was not triggering the didSelectRowAtIndexPath method when running in iOS6, but it was working fine in iOS5.1.

I had also implemented the

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
    return NO;
}

and returned NO. In iOS5 it was all working fine, but the minute I switched to iOS6 it would cease to trigger the didSelectRowAtIndexPath. Once I removed that shouldHighlightRow method, everything worked in iOS6 again. Cheers!

5
  • I did not implement the shouldHighlightRowAtIndexPath: method in my code. It's interesting how many different reasons there seem to be for what superficially looks like the same problem. Glad you found a solution! Dec 21, 2012 at 7:51
  • That was the reason for me. Interesting...not sure why/how this even effects it...
    – KVISH
    Dec 30, 2012 at 22:29
  • Just got caught out by this and wasted half an hour. Thanks +1
    – Darren
    Mar 13, 2013 at 10:08
  • @sergey glotov now i am facing the same problem with ios7. and dont know how to fix this Sep 6, 2013 at 9:41
  • @AnuragSoni It is not my answer, I'm just changed formatting in it. Sep 7, 2013 at 7:51
5

The usual reason that didSeletRowAtIndexPath() doesn't get called is having a UITapGestureRecognizer on your viewcontroller with Cancels touches in view set to YES.

The correct and only sensible fix is to set Cancels touches in view to NO. Then your table row selection should work nicely.

Obviously this has some implications in your gesture handlers - you may need to add some code to your gesture handler to stop some touches going on to your views i.e.

- (IBAction)onTapGesture:(UITapGestureRecognizer *)sender {

    if (sender.view == someOldViewThatINeedToDealWith) {
        sender.cancelsTouchesInView = true;
    }
}
4

I tried all the other answers posted, and although they seemed promising, they didn't solve the problem.

I've since discovered the cause of problem in my case: I was calling [self.tableView reloadData] on a different thread (due to handling an NSNotification event posted from a background worker thread).

I fixed the problem by changing [self.tableView reloadData] to

[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

Hope this helps.

1
  • Thank you. I was doing lot of background work, and was updating table in a BG thread. Aug 10, 2015 at 6:12
2

The other suspect could be a Tap Gesture Recognizer set to the view controller's view swallowing all taps like a blackhole. Remove the gesture recognizer will enable did select. I just had the same issue and the tap gesture was the cause.

1

The resolution is really weird: the UITableViewController registered for all notifications. In the handler for the notifications, the table view data was being reloaded using

[self.tableView reloadData]

According to Apple DTS, when the table reloads data, this causes a notification to be sent to the observer, causing a race condition ...

No explanation for why it would work sometimes or why it would always work on an iPhone. But registering only for a small subset of notifications (i.e. the ones I was really interested in) fixed the problem!

1

Setting

recognizer.cancelsTouchesInView = NO;

takes care of it if your use case allows simultaneous handling of touches by [tap] gesture recognizer (kdb dismiss for example) and the view the recognizer is attached to.

1
  • I have a BaseViewcontroller "Parent" (with UIGestureRecognizerDelegate), and a MenuViewcontroller "Child" the latter has a TableView inside. with your line of code remove the problem of not recognizing a single touch in the tableView, because it was necessary to make Touch with two fingers to interact with the cellView, but my solution complete is: @interface MenuViewController ()<UIGestureRecognizerDelegate> -(void)ViewDidLoad{ .... [self.tableViewMenu addGestureRecognizer:tapGestureRecognizer]; tapGestureRecognizer.cancelsTouchesInView = NO; Jul 10, 2018 at 16:10
0

in my case I hade button which received all touch events before tableviewcell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.