0

My application uses UITextView to enter text in chat view. I added a placeholder to this by using this answer. The problem occurs when trying to delete longer marked text, then the program falls into infinite loop. For shorter texts the program works correctly and removes selected text. Do you have any idea what might be wrong? How to fix it?

    func textViewDidChangeSelection(_ textView: UITextView) {
    if placeholderState == .enabled {
        if self.window != nil {
            textView.selectedTextRange = textView.textRange(from: textView.beginningOfDocument,
            to: textView.beginningOfDocument)
        }
    }
}

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee7df4fb8)

Coder
  • 508
  • 2
  • 13
Wojciech Konury
  • 161
  • 1
  • 3
  • 11

1 Answers1

0

Changing selectedTextRange will call again textViewDidChangeSelection of the delegate. If you want to change the selection behavior of your text view, you can subclass UITextView.

Amon
  • 121
  • 4