0

I have a UITextView in a TableViewCell and I wanted to enable data detection in the textView in order to show clickable links and Phone numbers. So I did this in storyBoard

Behaviour: Editable, DataDetectors : Link,Phone Number

User Interaction enabled

These steps didn't work so I did the same in code.

  @IBOutlet weak var postDescTextView: UITextView!

 override func layoutSubviews() {
    super.layoutSubviews()
    postDescTextView.isUserInteractionEnabled = true
    postDescTextView.isSelectable = true
    postDescTextView.dataDetectorTypes = .all

}

But none of the steps seems to work.

Simulator Screen Shot

There is clearly something I'm doing wrong. I'm pretty sure the answer is a simple one. I've found some similar questions like these. Question 1 Question2

But unlike these questions, I don't want my TextView editable nor I don't want to be able to select The TableViewCell. Just need to make the Datalink detection work in a TableViewCell.

John Xavier
  • 73
  • 1
  • 12

1 Answers1

1

If you're trying to make postDescTextView programmatically remove everything else and add the following.

postDescTextView.isEditable = false
postDescTextView.dataDetectorTypes = .all

Or if you have a storyboard

enter image description here

Note: If you're using the programmatic approach there is no need for giving it in viewDidLayout which gets called every time there's a layout change. Give it in the init method instead.

Frankenstein
  • 15,732
  • 4
  • 22
  • 47