views:

285

answers:

4

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?

+1  A: 

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 :-)

Phil Nash
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
A: 

Maybe you should also call setNeedsLayout and/or layoutIfNeeded?

Adam Woś
Did both and also in combinations, but to no use. Somebody help me plzz...
wolverine
A: 

Try something like performSelectorOnMainThread:withObject:waitUntilDone:

Nimrod
But I have tried it and u can see it on the code above.
wolverine
Doh. Must have stayed up too late last night.....
Nimrod
A: 

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