Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
Ios NSTextView,长NSMutableAttributedText滚动和加载速度低_Ios_Uitextview_Nsattributedstring_Nsmutableattributedstring - Fatal编程技术网

Ios NSTextView,长NSMutableAttributedText滚动和加载速度低

Ios NSTextView,长NSMutableAttributedText滚动和加载速度低,ios,uitextview,nsattributedstring,nsmutableattributedstring,Ios,Uitextview,Nsattributedstring,Nsmutableattributedstring,我有一个uitextview,大多数时候应该显示longattributedtexts。我使用以下代码创建我的属性文本: //Add each line of doa to an element of array for future usage NSArray *paragraphs = [self.Text componentsSeparatedByString:@"\r\n"]; MixedContent= [[NSMutableAttributedString all

我有一个
uitextview
,大多数时候应该显示long
attributedtexts
。我使用以下代码创建我的属性文本:

 //Add each line of doa to an element of array for future usage
    NSArray *paragraphs = [self.Text componentsSeparatedByString:@"\r\n"];

    MixedContent= [[NSMutableAttributedString alloc]init];
    ArabicContent= [[NSMutableAttributedString alloc]init];
    TranslatedContent= [[NSMutableAttributedString alloc]init];

    NSString * temp=@"";

    for (int i=0; i< paragraphs.count; i++) {

        if([paragraphs[i] hasPrefix:@"$2."]){

            temp=  [paragraphs[i] stringByReplacingOccurrencesOfString:@"$2." withString:@"" options:1 range:NSMakeRange(0, 3)];

            NSMutableAttributedString* tempMutable=  [[NSMutableAttributedString alloc] initWithString:temp attributes:doaDescriptionAttributes];

            //Go to next line
            [tempMutable  appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"\n\n"]];


            [ArabicContent appendAttributedString: tempMutable];

            [TranslatedContent appendAttributedString:tempMutable];

            [MixedContent appendAttributedString:tempMutable];


        }else if ([paragraphs[i] rangeOfString:@"$3."].location != NSNotFound){

            temp=  [paragraphs[i] stringByReplacingOccurrencesOfString:@"$3." withString:@"" options:1 range:NSMakeRange(0, 3)];

            NSMutableAttributedString* tempMutable=  [[NSMutableAttributedString alloc] initWithString:temp attributes:arabicDoaAttributes];

            [MixedContent appendAttributedString:tempMutable];
            [MixedContent  appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"\n"]];

            [ArabicContent appendAttributedString:tempMutable];
            [ArabicContent appendAttributedString: [[NSMutableAttributedString alloc] initWithString:@" "]];

        }else if ([paragraphs[i] rangeOfString:@"$4."].location != NSNotFound){

            temp=  [paragraphs[i] stringByReplacingOccurrencesOfString:@"$4." withString:@"" options:1 range:NSMakeRange(0, 3)];

            NSMutableAttributedString* tempMutable=  [[NSMutableAttributedString alloc] initWithString:temp attributes:arabicDoaAttributes];

            [MixedContent appendAttributedString:tempMutable];
            [MixedContent  appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"\n"]];

            [TranslatedContent appendAttributedString:tempMutable];
            [TranslatedContent appendAttributedString: [[NSMutableAttributedString alloc] initWithString:@" "]];
        }

        temp=nil;
    }

}
问题是,当我设置或更改此
textview
的文本时,应用程序设置或更新文本大约需要2秒钟。等待时间对我的用户不好

而且,当我滚动文本视图时,它一点也不好。它滚动一些段落,然后停下来,然后滚动,停下来,滚动

实际上,滚动速度很慢

有没有更好的方法来设置文本,使我有更好的表现

更新

我想是否可以通过滚动加载文本。一些东西,比如一个懒惰的加载程序列表,但是对于uitextview。可能吗

更新

当我添加没有任何属性的文本时。(我指的是所有颜色相同的线条)卷轴很好用

更新


这是关于文本的数量。当我减少文本数量时。例如,我没有设置10000个字符,而是设置了500个字符,现在速度非常快。如何修复它?

与其将所有文本放在一起,然后尝试设置它,不如将部分文本附加到UITextView的attributedText。类似于[self.myTextView.attributedText appendedtributedstring:yourString]的东西,我认为它可以解决加载时间问题,但不会解决滚动问题。让我检查一下,滚动问题听起来好像有些慢了下来,然后试图赶上你们的互动。如果加载时间是固定的,则也可能有助于解决滚动问题。uitextview.AttributeText是NSAttributeText而不是NSMutableAttributeText,因此它没有appendAttributedStrig方法
self.myTextView.attributedText= myAttributedText;