I have a really long string, with thousands of line with a default font. So rather than draw the whole thing out in one table view cell, I’m going to make several cells to draw the same string, each drawing the next part of the string.
I’m having a hard time finding a starting point. Say I draw the first 500 pixels of height of the string in the rect – how do I know where to start in my second rect? If it’s the same string, how can I specify for it to draw only some parts of the string?
Each cell will know it’s own row number, so I’ll be able to determine where exactly in the table I am, I just don’t know how the string will know which part it’s supposed to draw..
Or another question would be: how can I break up one string into multiple strings based on a certain number of lines?
Edit: Here are some NSString methods I’m finding that might be useful, but I still don’t know how I would use them in my case:
- (void)getLineStart:(NSUInteger *)startIndex end:(NSUInteger *)lineEndIndex contentsEnd:(NSUInteger *)contentsEndIndex forRange:(NSRange)aRange
- (NSRange)lineRangeForRange:(NSRange)aRange
Use
substringWithRange:This will allow you to select a start and end point of the string. I would grab each section by a number of characters. So section 1 would be 0-500 section 2 would be 500-1000. The problem here would be you may cut off in the middle of a sentence. You can use something like lineRangeForRange to determine your ranges for the substring.EDIT
Log displays:
So what this did was I supplied LineRangeForRange a range which was from zero to half of the string. It could the last end line “\n” with in that range. Then I grabbed that substring