Only first link is detected in uitextview

爷,独闯天下 提交于 2020-01-17 11:14:46

问题


I have strange problem with url detection in textView. My code is like this:

_contactDescription.dataDetectorTypes = UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber;
[_contactDescription setUserInteractionEnabled:YES];
[_contactDescription setSelectable:YES];
[_contactDescription setEditable:NO];
_contactDescription.delegate = self;
_contactDescription.text = desc;

My string has a lot of phone numbers and emails to detect but using data detection only first phone and first email run action on tap. All phones and emails are highlighted but no action on tap.

Does anyone had similar problem ? Thanks in advance.


回答1:


If they are highlighted but you can't click them, but you can click the first one, that usually means that there is another view you didn't expect over lapping the text. You could try adding this in your view controller to see what is getting tapped.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    for (UITouch * touch in [touches allObjects])
    {
        NSLog(@"View: %@", touch.view);
    }
}

Or run it in the simulator and in Debug turn on Color Blended Layers

Or try hiding all other views until it works to find the offender.

Another issue could bet the text is actually outside the view and you can't tell because it isn't clipping the extra. To verify that isn't the case.

[_contactDescription setClipsToBounds:YES];

Hopefully that is the case and one of those help find the offender. Good luck.



来源:https://stackoverflow.com/questions/28581546/only-first-link-is-detected-in-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!