小编Pie*_*ani的帖子

NSTextStorage的子类导致访问链接崩溃

我正在构建一个自定义NSTextStorage类来查找和匹配自定义用户输入并在我的应用程序中处理它.所以我遵循了几个教程,最着名的是objc.io,并创建了一个子类,并将其设置layoutManager为UITextView通过nib创建的相同:

-(void)setCustomTextStorage:(NSTextStorage *)customTextStorage
{
    if (_customTextStorage != customTextStorage)
    {
        _customTextStorage = customTextStorage;
        [_customTextStorage addLayoutManager:self.textView.layoutManager];
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在覆盖processEditing的NSTextStorage子类,并添加NSLinkAttributeName适当.

顺便说一下,这里有示例应用程序,请务必签出custom-text-storage分支或只是在这里阅读差异这个问题

现在,当用户点击实际链接时,我得到一个崩溃应用程序的异常:

2014-08-20 23:06:45.223 JSQMessages[63170:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSConcreteTextStorage attribute:atIndex:effectiveRange:]: Range or index out of bounds'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001025d2495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001021a999e objc_exception_throw + 43 …
Run Code Online (Sandbox Code Playgroud)

uikit ios textkit

6
推荐指数
1
解决办法
470
查看次数

标签 统计

ios ×1

textkit ×1

uikit ×1