开发者

How to force screen update for UIScrollView from non-UI thread/function (iPhone)

I am drawing a set of images on the uiscrollv开发者_如何学Goiew 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?


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


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];   
 } 
}


Maybe you should also call setNeedsLayout and/or layoutIfNeeded?


Try something like performSelectorOnMainThread:withObject:waitUntilDone:

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜