1

I've an UITabBarController. In my UIViewController a UItextView where I can select the text but when I change the View, text is kept selected. I've tried to add that code but doesn't work:

var range:NSRange = textView.selectedRange
range.length = 0
range.location = NSNotFound

1 Answers1

1

Did you try setting textView.selectedTextRange = nil?

Edit: Depending on your requirements, could you set this in viewWillDisappear or viewWillAppear so it is deselected when you either leave or come back to your view controller?

Similar to: How do I deselect text in UITextView?

Community
  • 1
  • 1
jday
  • 578
  • 6
  • 14
  • If I stay in that `UIViewController` that work but if I change they kept that information.. I think `UITabBarController` save that data. @jday001 –  Jan 27 '15 at 20:25
  • sorry if I didn't write before but I've already tried to write in `viewDidDisappear` and `viewWillDisappear` func, but it doesn't work.. –  Jan 27 '15 at 20:32
  • is `textView` an `IBOutlet`? – jday Jan 27 '15 at 20:34
  • and just to be sure, is the textView connected to the IBOutlet in the storyboard? – jday Jan 27 '15 at 20:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69693/discussion-between-mala-and-jday001). –  Jan 27 '15 at 21:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69748/discussion-between-mala-and-jday). –  Jan 28 '15 at 15:28