0

I have a UITextView inside my custom UITableViewCell. I am using UITextView basically for providing data detection on cell. I have my own custom UIMenuitems set for different cells.

              |-------------------------------|
              |                               |
              |   |------------------|        |
              |   |                  |        |
              |   |        UITextView|        |
              |   |__________________|        |
              |                               |
              |                UITableViewCell|
              |_______________________________|

Issue that I am facing is that when I tap the area within UITextView i don't get any menu controller, the expected behavior is, it should call same menu controller that is define for that particulate UITebleViewCell.

If I replace UITextView with UILabel i get proper menu controller but I loose data detection capability.

Please guide me in proper direction, what am I missing or what I am doing wrong?

Umang
  • 129
  • 1
  • 3
  • 9

1 Answers1

1

You can use UITapGestureRecognizer to detect a tap on your textview.

  • Make sure userInteractionEnabled is TRUE for your textView

myTextView.userInteractionEnabled = TRUE;

  • Add gesture recognizer for your text view
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myTextViewTapped:)];
[myTextView addGestureRecognizer:tapGestureRecognizer];
  • Display menu controller on tap
- (void)myTextViewTapped:(id)sender {
    NSLog(@"my text view is tapped");
    // display menu now!

}
  • If your menu controller depends on individual cell then you can use the row number as tag of your textView and display relevant menu controller
// in your tableview cellForRowAtIndexPath method

myTextView.tag = indexPath.row;

// in your selector

UITextView *myTextView = (UITextView *)sender;
int rowNumber = myTextView.tag;
Subhransu
  • 108
  • 4