Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在UITextView中获取行范围的更好方法_Objective C_Search_Line Numbers_Uitextposition - Fatal编程技术网

Objective c 在UITextView中获取行范围的更好方法

Objective c 在UITextView中获取行范围的更好方法,objective-c,search,line-numbers,uitextposition,Objective C,Search,Line Numbers,Uitextposition,现在,通过使用段落粒度的标记器循环,我能够获得包含n行的UITextView中每行的文本范围。不幸的是,这意味着我对文本中第m行的搜索算法是n阶的。除了让我的算法记录n之外,还有什么更简单的方法可以让我找到范围吗?以下是我目前如何找到我的文本范围: - (UITextRange *)textRangeOfLineAtIndex:(NSUInteger)index { UITextPosition *position = self.beginningOfDocument; N

现在,通过使用段落粒度的标记器循环,我能够获得包含n行的UITextView中每行的文本范围。不幸的是,这意味着我对文本中第m行的搜索算法是n阶的。除了让我的算法记录n之外,还有什么更简单的方法可以让我找到范围吗?以下是我目前如何找到我的文本范围:


- (UITextRange *)textRangeOfLineAtIndex:(NSUInteger)index {

    UITextPosition *position = self.beginningOfDocument;

    NSUInteger lineCount = 0;
    while([self comparePosition:self.endOfDocument toPosition:position] == NSOrderedDescending && lineCount < index) {
        position = [self.tokenizer positionFromPosition:position toBoundary:UITextGranularityParagraph inDirection:UITextStorageDirectionForward];
        ++lineCount;
    }

    return [self rangeEnclosingPosition:position withGranularity:UITextGranularityParagraph inDirection:UITextStorageDirectionForward];

}

-(UITextRange*)textRangeofLineIndex:(NSInteger)索引{
UITextPosition*position=self.beginingofDocument;
整数行数=0;
while([self-comparePosition:self.endOfDocument-toPosition:position]==sensorderedescending&&lineCount