0

我正在尝试制作一个irc客户端。我保留一个 NSTextView 对象,并且我有一个包含 NSTextStorage 对象的容器类。每次用户单击“频道按钮”时,我都会使用 NSTextView 的 layoutManager 替换 NSTextStorage 对象。存储的文本采用 NSAttributedString 的形式,因为我想要不同颜色的部分文本。

我在 NSTextStorage 中存储 NSAttributedString 的方式是我从容器对象中获取指针并在其上使用 appendAttributedString。

而且我在 NSLog 中遇到了一个未捕获的异常并且没有中断。你能帮我找出问题所在吗?

2015-09-14 08:25:49.776 ircX[3248:128903] *** -[NSConcreteTextStorage attributesAtIndex:effectiveRange:]: Range or index out of bounds
2015-09-14 08:25:49.780 ircX[3248:128903] (
    0   CoreFoundation                      0x00007fff9974503c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff99c0176e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff99744eed +[NSException raise:format:] + 205
    3   UIFoundation                        0x00007fff939c7d77 -[NSConcreteTextStorage attributesAtIndex:effectiveRange:] + 127
    4   AppKit                              0x00007fff94e05ffc -[NSTextView(NSSharing) setSelectedRanges:affinity:stillSelecting:] + 2525
    5   UIFoundation                        0x00007fff939a53af -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 423
    6   UIFoundation                        0x00007fff939c7291 -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 152
    7   UIFoundation                        0x00007fff939c6d93 -[NSTextStorage processEditing] + 198
    8   UIFoundation                        0x00007fff939c6c98 -[NSTextStorage edited:range:changeInLength:] + 312
    9   Foundation                          0x00007fff925935e3 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 330
    10  UIFoundation                        0x00007fff939c87c1 __71-[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:]_block_invoke + 52
    11  UIFoundation                        0x00007fff939c8703 -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 136
    12  ircX                                0x000000010000b68b -[IRCWindow addData:] + 3371
    13  ircX                                0x000000010000195f -[ViewController updateTextView] + 527
    14  Foundation                          0x00007fff9259f953 __NSFireTimer + 95
    15  CoreFoundation                      0x00007fff996982e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    16  CoreFoundation                      0x00007fff99697f73 __CFRunLoopDoTimer + 1059
    17  CoreFoundation                      0x00007fff9970b53d __CFRunLoopDoTimers + 301
    18  CoreFoundation                      0x00007fff99653608 __CFRunLoopRun + 2024
    19  CoreFoundation                      0x00007fff99652bd8 CFRunLoopRunSpecific + 296
    20  HIToolbox                           0x00007fff962a956f RunCurrentEventLoopInMode + 235
    21  HIToolbox                           0x00007fff962a92ea ReceiveNextEventCommon + 431
    22  HIToolbox                           0x00007fff962a912b _BlockUntilNextEventMatchingListInModeWithFilter + 71
    23  AppKit                              0x00007fff94d6c8ab _DPSNextEvent + 978
    24  AppKit                              0x00007fff94d6be58 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
    25  AppKit                              0x00007fff94d61af3 -[NSApplication run] + 594
    26  AppKit                              0x00007fff94cde244 NSApplicationMain + 1832
    27  ircX                                0x00000001000020b2 main + 34
    28  libdyld.dylib                       0x00007fff8ec045c9 start + 1
)
4

0 回答 0