4

I've got two UITextViews containing data that should be recongised by the data detection, however whilst one works fine on both device and simulator there's one that only works under Simulator. I've attempted trashing the build from my device, cleaning the product down, removing derived data and nothing seems to resolve the inconsistency.

Link detection was enabled within Interface Builder, the data is passed in with a NSString stringWithFormat: formatted string and set with UITextView setText:. Set the same way for both, so there's no difference there, but it just doesn't seem to work correctly for one of them.

EDIT: On the device if I tap on one of the items that should detect as a link, it'll then turn blue and do link detection. I'm not setting any custom fonts or colours that could have an impact.

Nicholas Smith
  • 11,642
  • 6
  • 37
  • 55

2 Answers2

6

It appears that the trick is to setScrollable:NO. Seems to fix the problem, although if you need scrolling, I'm not sure what the answer will be...

Darren Oster
  • 9,146
  • 10
  • 48
  • 66
  • Worked for me, but there was still a very special case, that caused problems: When a box began with a link and the text was set to empty text (@"" - not nil!) the box somehow "broke" and from then on any new text in that box became a link. My solution was to override setText to set [super text] to @"x" first and then to the actual new text. – Tharagon Nov 07 '13 at 10:59
  • WOW! Awkward but awesome solution! – Klaas Mar 03 '14 at 22:41
1

Apparently this issue is caused by how iOS is currently handling the UITextView links. It is creating an NSAttributedString that turns sections of the text blue ( when the view contains a link ). So I've figured out that this bug only occurs when a link is the first text in the AttributedString, i.e. the first text in the text view. So it's easily fixed by prepending an whitespace to your text before setting it. Or overriding setText to " " + text;

Hope this helps guys

mrmichaeldev
  • 329
  • 3
  • 11
  • 2
    Exact duplicate of [your answer](http://stackoverflow.com/questions/19121367/uitextviews-in-a-uitableview-link-detection-bug-in-ios-7/22457853#22457853). Please stop posting duplicate answers, rather post a single and give link here for the reference. – Paresh Mayani Mar 17 '14 at 16:33
  • 1
    This seems to be the correct observation, but the proposed solution is less helpful. Did you file a bug report with Apple? – Bjørn Ruthberg Mar 31 '15 at 10:31
  • I did not, I hadn't thought about it at the time. – mrmichaeldev Mar 31 '15 at 20:25