0

To allow user interaction with links I use code like this:

UITextView *t1 = [UITextView new];
[self.view addSubview:t1];
t1.frame = self.view.frame;

t1.font = [UIFont systemFontOfSize:16];
t1.text = @"go to http://apple.com";
t1.dataDetectorTypes = UIDataDetectorTypeLink;
t1.editable = NO;

But if I need to set new text, it reuse style:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    t1.text = @"test";
});

Will show "test" like link (blue color) but without link behaviour (go to link, context menu). I didn't find in documentation why this is legal.

As I understand the only way to "fix" this is reset attributes like font, text color to initial values.

John Tracid
  • 3,836
  • 3
  • 22
  • 33
  • possible duplicate of [UITextViews in a UITableView link detection bug in iOS 7](http://stackoverflow.com/questions/19121367/uitextviews-in-a-uitableview-link-detection-bug-in-ios-7) – John Tracid Nov 03 '14 at 11:40

1 Answers1

0

I found this way to fix:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    t1.dataDetectorTypes = UIDataDetectorTypeNone;
    t1.dataDetectorTypes = UIDataDetectorTypeLink;
    t1.text = @"another text with http://link.com link";
}); 

But maybe there is more correct/elegant solution.

John Tracid
  • 3,836
  • 3
  • 22
  • 33