UIProgressView progress doesn't updated
I have a UIProgressView added to self.view as subview. I have a UITableView with rows loaded. I need image in every row but I don't want the app to wait for all of them, so I decide to run NSThread with loading images process. When I try to update progress of the UIProgressView from inside my thread - it doesn't get updated. Do I need to implement some delegates maybe?
Initialization
progressView = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[progressView setFrame:CGRectOffset(CGRectMake(0, 0, 320, 8), 0, 1)];
[self.view addSubview:progressView];
Then I run my thread
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[progressView setProgress:0.0];
NSThread *myThread = [[NSThread alloc] initWithTarget:self
selector:@selector(imageLazyLoading)
object:nil];
[myThread start];
[pool release];
[myThread release];
Then I try to update it
CGFloat pr;
for(int i=0; i < [self.itemsToDisplay count]; i++){
if (!runThread) {
return;
}
pr = (CGFloat)i/(CGFloat)[self.itemsToDisplay count];
[self performSelectorOnMainThread:@selector(updateProgressBar:)
withObject: [NSNumber numberWithFloat:pr]
wait开发者_JAVA百科UntilDone: YES];
progressView.progress += 0.5;.............
and nothing at all....
I had the same problem with iOS 5.0. Seems that up until 5.0, you could update the 'progress' variable from any thread, but the setNeedsDisplay must be called from the main thread. From 5.0 and onwards, you must set the 'progress' value from the main thread as well. Hope it helps anybody.
All you have to do is , update the Progressview
on Main Thread. Here is the article about it.
http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/
精彩评论