开发者

How I update a scroll view?

开发者 https://www.devze.com 2023-01-05 16:16 出处:网络
I, sorry for my english I\'m not very good, I code in objective-c, I try to set text in a uiscrollview and update the content of the scr开发者_C百科ollview right after. I have a loop and I set the tex

I, sorry for my english I'm not very good, I code in objective-c, I try to set text in a uiscrollview and update the content of the scr开发者_C百科ollview right after. I have a loop and I set the text with the method [uiscrollview setText:] in that loop, but the text is only displayed in the scrollview at the end of the loop...

thanks Alex


  1. Since when the UIScrollView has a text property?.. Do you mean UITextView?

  2. If the loop is in main thread then the UI will probably be updated only after completing the method (with the loop inside) - just like you write. Possible solution might be to execute the method with the loop in the background thread (e.g. [self performSelectorInBackground:@selector(updateScrollViewInLoop) withObject:nil];) and inside the loop update the scroll view in the main thread ([uiscrollview performSelectorOnMainThread:@selector(setText:) withObject:text waitUntilDone:YES];).

  3. You might also add [uiscrollview setNeedsDisplay]; line right after updating the text. I'm not sure it will help because of the second point above and, in addition, I think that this line is called in the background anyway once you change the content of the scroll view...


You first need to build your string, then call set text. Set text first clears the existing text. Also, I am assuming you mean UITextView (a subclass of UIScrollView) as it has a 'text' property. Try:

NSString *text = [NSString string];

for (NSString *line in lines)
{
  text = [text stringByAppendingString:line]; 
}

[self.textScrollView setText:text];
0

精彩评论

暂无评论...
验证码 换一张
取 消