views:

209

answers:

1

I have some text which might or might not contain web URLs, phone numbers, email links etc. which UIWebView automatically detects as hotspots.

Question: I want to show this text in UIWebView ONLY when there are one or more hotspots, but as plain text if it doesn't. So how can I detect this in code?

Additional Info: JavaScript code below tells how many <a href="...">...</a> links there are. This does NOT count how many other "link" items there are. For example "Link to www.yle.fi" contains one link according to UIWebView, but zero according to JavaScript:

NSString *s = [webView stringByEvaluatingJavaScriptFromString:
                @"document.links.length"];

Still no answer to the question how to ask UIWebView how many links it has found...

A: 

You can use several regular expressions and check if the text matches those of URL/phone number/email addresses.

However, if your intention is simply let the user open a link, the UITextView is suffice.

Check the dataDetectorTypes property.

KennyTM
Sorry, not really answering my question... To use regular expressions I would need to know how UIWebView internal regex works. Not better, not worse, but in same way. Mission impossible.
JOM
UITextView uses same font and color for all text. Want to hilight hotspots for user, so UIWebView + custom CSS was the way to go. Just need to know when there is need to use it == are there any links. Can't believe it cannot be done! Hmm...
JOM
@JOM: (1) No need to use the internal regex! RegexKitLite is enough. (2) You need to *turn off* editable to get http://developer.apple.com/iphone/library/qa/qa2009/images/qa1495_Result.png.
KennyTM
JOM