3

I am drawing a set of images on the uiscrollview from a non-ui thread/function. But its only displayed after all the images are done drawing. For drawing all the images, I have written a function and that is what is being called as the non-ui thread. I did write this line inside the function

[self performSelectorOnMainThread:@selector(updateUI) withObject:nil waitUntilDone:NO];

And have written the function as given below

- (void)updateUI
{
[myScrollView setNeedsDisplay];
}

But its having no effect even when I can see the control being passed to that function. What to do now?

wolverine
  • 2,967
  • 5
  • 31
  • 35

4 Answers4

3

In my experience all drawing operations must be performed on the UI thread, even if they are not visible, or even added to the view hierarchy, when you are doing them. If you find a way around that I'd be keen to know, though :-)

philsquared
  • 22,403
  • 12
  • 69
  • 98
  • Another thing is that if I am just doing some action in the main thread(ie, scrollview), I am able to see each of them being loaded. But problem is that I cant say to the user to move the screen all the time so as to view it loading.:) – wolverine Jan 13 '10 at 14:48
  • "or even added to the view hierarchy" That was key for me, thanks! – Steven Stefanik Mar 09 '12 at 03:45
1

Ok, I got a solution. Its working perfectly even though I dont like the solution. I changed my function like this.

- (void)updateUI
{
 for(UIView *subview in [myScrollView subviews]) 
 {
  [myScrollView bringSubviewToFront:subview];   
 } 
}
wolverine
  • 2,967
  • 5
  • 31
  • 35
0

Maybe you should also call setNeedsLayout and/or layoutIfNeeded?

Adam Woś
  • 2,493
  • 20
  • 21
0

Try something like performSelectorOnMainThread:withObject:waitUntilDone:

Nimrod
  • 5,168
  • 1
  • 25
  • 39