1

So, I've added a UITableViewController and UITableViewCell into a UIViewController and while the cellForRowAtIndexPath delegate method works, didSelectRowAtIndexPath does not. Does anyone have any ideas?

  • EDIT 2: The delegate for the UITableView is set to the UIViewController.

  • EDIT 3: I found the answer to my issue on another Stack question here. Basically I had a UITap... on my [self view] that was blocking the didSelectRow.... I have no idea why the tap blocks the delegate method and I also have no idea how to get both the tap and the table working together simultaneously.

  • EDIT: The part that bugs me is that I've gotten this exact setup working on an earlier app. So that means I've missed a step somewhere along the way. The thing is, I've combed over all the steps and have compared previous app vs current app and I really have no idea what I missed.

I've added logging to both delegate methods and while one outputs, the other does not.

ViewController.h

#import "...TableViewCell.h" ... UITableViewDataSource, UITableViewDelegate ... 

ViewController.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"cellForRowAtIndexPath"); ... return Cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"didSelectRowAtIndexPath"); } 

...TableViewCell.h (contents not important)

...TableViewCell.m (contents not important)

4
  • 1
    Since the cellForRow... method is called we know the table's dataSource is set. Did you also set the table's delegate property? Without setting that the didSelectRow... method won't be called. Commented Sep 30, 2013 at 0:29
  • Hi rmaddy, yes, the UITableView delegate property is set to the UIViewController. *Edit: I accidentally said UITableViewController but I meant to say UIViewController. Commented Sep 30, 2013 at 0:41
  • 1
    Check very carefully that you spelled it correctly, with proper capitalization. Commented Sep 30, 2013 at 0:46
  • Hi Hot Licks, I just double checked (can never be too sure) and it's spelled exactly right, let me copy/paste here: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. Commented Sep 30, 2013 at 0:48

4 Answers 4

2

I found the answer on another StackOverflow question.

I had a UITapGestureRecognizer added to [self view] which I commented out, and then the delegate method worked.

Can anyone please tell me why this worked and also how I can get the UITapGestureRecognizer working on the same screen as the UITableView?

// Hide keyboard when user taps outside of it UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboardOnTap)]; //[[self view] addGestureRecognizer:tapGestureRecognizer]; 
  • EDIT: Corrected typo of UITapeGestureRecognizer to UITapGestureRecognizer
Sign up to request clarification or add additional context in comments.

1 Comment

Uh, I think that's "UITapGestureRecognizer". (And it is a bit mysterious. Best thing, if possible, is to add the recognizer to a subview that is not the one where you want to pick up touches in other ways.)
1

have you set the delegate of the tableView?

myTableView.delegate = self;

EDIT: My bad, did not read that cell for row is being called.

You say that you have used a custom tableViewController. If you have overridden the didSelectRowAtIndexPath method, it might be important to call [super didSelectRowAtIndexPath:] in the tableViewController

EDIT 2: One more thing. I do not know the reason for this, but I faced the same issue some time back in a viewController. I resolved it by adding an empty implementation of didDeselectRowAtIndexPathin the same viewController. Try adding it to your table's delegate controller.

1 Comment

Not your bad. One is from the dataSource and the other is from the delegate.
0

To answer to the question "how I can get the UITapGestureRecognizer working on the same screen as the UITableView";

You should "inform" your GestureRecognizer that other Recognizer can handle the same gesture:

You do that by implementing the method of UIGestureRecognizerDelegate

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

This is a small exemple...

@interface MyController : UIViewController<UIGestureRecognizerDelegate> { } @end -(void)viewDidLoad { UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionOnTapGesture:)]; [gr setNumberOfTapsRequired:1]; [gr setDelegate:self]; [self.view addGestureRecognizer:gr]; } -(BOOL) gestureRecognizer:(UIGestureRecognizer *) gestureRecognizer shouldRecognizeSimultaneouslyGestureRecognizer:(UIGestureRecognizer *) otherGestureRecognizer { return YES; } 

Comments

0

Check in the interface builder if the property selection is set to 'No selection'. Change it to 'Single selection' or other option according to your needs.

This might be the reason why didSelect is not getting triggered.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.