0

How can I make a read-only textview where each word can be touched on to open a popup?

The person will enter text and then submit it. They will then be taken to another page where I want to be able to programmatically make each word clickable in order to show the definition of the word in a pop-up.

At the very least I am looking for the terminology that should google and read up on.

Main question: How can I make words in a read-only textview touchable?

webmagnets
  • 2,266
  • 3
  • 33
  • 60

1 Answers1

0

If you just want to disable editing in textView but keep the cut copy paste or other functions alive, Use below:

- (BOOL)textView:(UITextView *)textView shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    return NO;
}

Also do not return NO from textViewShouldBeginEditing to keep the interaction alive.

Note: For operation on tapped words, you should use NSAttributedString and add UITapGestureRecognizer to the textView. You can follow the below question:

Detecting taps on attributed text in a UITextView in iOS

Community
  • 1
  • 1
bllakjakk
  • 5,045
  • 1
  • 18
  • 28
  • Thanks. How could I make each word respond to touchUpInside? – webmagnets Dec 14 '14 at 20:05
  • You have to use NSAttributedString and UIGesture. Follow this post. http://stackoverflow.com/questions/19332283/detecting-taps-on-attributed-text-in-a-uitextview-on-ios-7 – bllakjakk Dec 14 '14 at 20:19