ios - 用户界面 TextView /NSAttributedString : iOS Bug?

标签 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 = [[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”之类的内容,它就可以正常工作。这对我来说毫无意义。 亲自尝试一下,您就会明白我的意思。

最佳答案

我认为这里发生的事情是 NSLinkAttributevalue 应该是一个 NSURL,而不是一个字符串常量。

错误通知(... [__NSCFConstantString scheme] ...)它正在尝试发送 NSURL selector到一个常量字符串。

关于ios - 用户界面 TextView /NSAttributedString : iOS Bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34603969/

相关文章:

ios - 核心数据复杂的countForFetchRequest

ios - iOS 8 上的通用链接?

objective-c - 应用程序失去焦点隐藏窗口

ios - 将拍摄的图像分配给 ImageView

django - 在 Django 中退出调试时不会加载静态文件

android - 我必须在 list 中添加什么才能在实际设备上调试 Android 应用程序?

iPhone - 更新表后 sqlite 不工作

ios - 在 View Controller segue 之间传递数据

ios - 创建一个带有 Storyboard的自定义 cocoa pod

visual-studio - 在 Visual Studio 的监 window 口中展开所有值