My goal is to use TextKit to italicize, set the size of the text, etc. certain words.
To get started, I'm just trying to highlight a character in a text string. As a newbie to TextKit (and truly for programming in general), I follow the syntax highlighting topic for obc.io issue # 5.
When using the NSLayoutManager built into the UITextView I created, my text appears on the screen without any exceptions. When I set UITextView as the layout manager of my subclass of NSTextStorage in my view controller (below), I get errors for exception for invalid glyph indices.
_textStorage = [BBRSyntaxHighlightTextStorage new]; [_textStorage addLayoutManager: self.readerTextView.layoutManager];
Console output below:
_NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 528 2013-12-01 15:23:24.949 BibleReader[6077:70b] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange invalid char range 1 2013-12-01 15:23:24.956 BibleReader[6077:70b] !!! _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 528 2013-12-01 15:23:24.957 BibleReader[6077:70b] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange invalid char range 1 2013-12-01 15:23:24.957 BibleReader[6077:70b] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange character count mismatch 2013-12-01 15:23:24.958 BibleReader[6077:70b] !!! _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 4040 2013-12-01 15:23:24.959 BibleReader[6077:70b] !!! _NSGlyphTreeInvalidateGlyphsForCharacterRange invalid char range 1
I read Apple Programming Guide many times and I think I understand how the text system is installed, but I have no idea why my glyph count will exceed the number of glyphs ...
I created a gist for my subclass of viewController and NSTextStorage, here and here , respectively.
ios objective-c textkit nstextstorage nslayoutmanager
jefffreyallen
source share