Reputation: 37
I am getting the following crash error when I click on a custom link I made inside my UITextView.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString scheme]: unrecognized selector sent to instance 0x10e7aa098'
This is what my code looks like.
NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] initWithString: @"20151230copy.png"];
NSRange range = NSMakeRange(0, [attrString length]);
[attrString beginEditing];
[attrString addAttribute:NSLinkAttributeName value:@"https://www.youtube.com/" range:range];
[attrString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:range];
[attrString addAttribute:
NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:range];
[attrString endEditing];
self.textView.attributedText = attrString;
I don't see what I am doing wrong and I think this might be an iOS bug. If I replace 20151230copy with something like "texas" it works fine. This makes no sense to me. Try this out for yourself and you will see what I mean.
Upvotes: 0
Views: 243
Reputation: 247
Apple Doc: NSLinkAttributeName The value of this attribute is and NSURL object (preferred) or an NSString object. The default value of this property is nil, indicating no link.
Available in iOS 7.0 and later.
Upvotes: 0
Reputation: 54640
I think what's happening here is NSLinkAttribute
's value
should be an NSURL
, not a string constant.
Notice in the error (... [__NSCFConstantString scheme] ...
) it is trying to send an NSURL selector to a constant string.
Upvotes: 3