UITextView/NSAttribute字符串:iOS错误?
当我单击在UITextView中创建的自定义链接时,出现以下崩溃错误UITextView/NSAttribute字符串:iOS错误?,ios,objective-c,debugging,crash,uitextview,Ios,Objective C,Debugging,Crash,Uitextview,当我单击在UITextView中创建的自定义链接时,出现以下崩溃错误 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString scheme]: unrecognized selector sent to instance 0x10e7aa098' 这就是我的代码的样子 NSMutableAttributedString* attrString
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString scheme]: unrecognized selector sent to instance 0x10e7aa098'
这就是我的代码的样子
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;
我不知道我做错了什么,我认为这可能是一个iOS错误。如果我将20151230copy替换为类似“texas”的内容,它就可以正常工作。这对我来说毫无意义。
你自己试试看,你就会明白我的意思。我认为这里发生的是
NSLinkAttribute
的值应该是NSURL
,而不是字符串常量
请注意,在错误(…[\uu NSCFConstantString scheme]…
)中,它试图向常量字符串发送一个值。我认为这里发生的是NSLinkAttribute
的值应为NSURL
,而不是字符串常量
请注意,在错误(…[\uu NSCFConstantString scheme]…
)中,它正试图向常量字符串发送一个字符串。Apple文档:
NSLinkAttributeName
此属性的值为and NSURL对象(首选)或NSString对象。此属性的默认值为nil,表示没有链接
iOS 7.0及更高版本提供。Apple文档:
NSLinkAttributeName
此属性的值为and NSURL对象(首选)或NSString对象。此属性的默认值为nil,表示没有链接
在iOS 7.0及更高版本中可用。您必须在NSLinkAttributeName的值中传递NSURL而不是NSString您必须在NSLinkAttributeName的值中传递NSURL而不是NSString