Reputation: 15247
I have a tableView
with tableViewCells
cell
that show a textView
.
textView
uses an attributedString
with custom URL link information, set up in tableView:cellForRowAtIndexPath:
as shown in this tutorial:
NSMutableAttributedString *attributedDisplayString = [[NSMutableAttributedString alloc] initWithString:displayString];
[attributedDisplayString addAttribute:NSLinkAttributeName
value:[NSString stringWithFormat:@"username://%@", userName]
range:NSMakeRange(0, userName.length)];
cell.textView.attributedText = attributedDisplayString;
When I tap the link, textView:shouldInteractWithURL:inRange:
is called in the delegate, thus the custom URL link has been detected and responds.
However, the supplied URL is nil
.
What am I missing?
Upvotes: 1
Views: 598
Reputation: 15247
Sorry for asking too fast. I found the problem, but maybe this helps others:
My variable userName
simply contained a space
, and could thus not be converted to a URL
.
After removing the space, it works.
To make a string that can be used for a URL, one can use in iOS8 and earlier
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
and in iOS9
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]
Upvotes: 1