views:

37

answers:

2

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 scrollview 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

A: 

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];
Kevin Sylvestre
A: 
  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...

Michael Kessler
Hi, sorry it's a scrollview now not a uitextview, but now I don't put text in it I add subview like label and button in my loop, when I call the method with the loop in background, I just take this line:[self performSelectorInBackground:@selector(updateScrollViewInLoop) withObject:nil];) and replace "updateScrollViewInLoop" by my method[objectdownloadFile downloadFile:urlWeb:scrollViewTelecharger]; is it?? because it don't compile...thanks againAlex
Alex