0

I have a UITableView with some UITableViewCells that contain labels with suggestions for text to be inserted into a UITextView. I want that when the user taps on some uitableviewcell with text suggestion, this text will enter the uitextview, but I also want that the user will be able to edit the uitextview by himself.

All was working fine until I wanted to add the ability to tap on the background after start editing the textview, with this resulting in hiding the keyboard (resignFirstResponder). But when I implemented backgroundTap, the calls to didSelectRowAtIndexPath ceased to happen.

How can I solve this, so that when the user taps on some uitableviewcell, the call will be to didSelectRowAtIndexPath instead of to backgroundTap?

My implementation of backgroundTap is:

   -(void)backgroundTap:(UITapGestureRecognizer *)tapGR{
       //...some code here...
   }

In the viewWillAppear I added the line:

[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTap:)]];

Thanks.

Tomer
  • 189
  • 1
  • 3
  • 11
  • Nowhere near enough info! Sure, I have a guess as to what you did, but can't you make some attempt to be open about it? Tell us *how* you "implemented BackgroundTap". Gosh, maybe even show some (gasp) code. – matt Apr 08 '13 at 16:07
  • I don't know how my code can help because my question is about the principals. The calls aren't being made. Anyway, I posted my code. – Tomer Apr 08 '13 at 16:12
  • Your code can help because the info that you have attached a gesture recognizer to something is *crucial*. You didn't say that before. Okay, but now I need to know what the gesture recognizer is attached to; show the code that creates and attaches it, if there is any. Or describe what it is attached to. – matt Apr 08 '13 at 16:17

1 Answers1

1

The problem is that the tap gesture recognizer eats the taps intended for the table view. See didSelectRowAtIndexPath: not being called.

A gesture recognizer applies not only to the view to which it is attached (self.view in your case) but also to all that view's subviews all the way down the view hierarchy. In this case, that includes everything, including your table view cells.

The solution is to mediate with a gesture recognizer delegate (iOS 5) or with UIView gestureRecognizerShouldBegin: (iOS 6 only).

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141