我有一个 UIProgressView 添加到 self.view 作为子视图。我有一个加载了行的 UITableView。我需要每一行中的图像,但我不希望应用程序等待所有图像,所以我决定运行 NSThread 并加载图像过程。当我尝试从线程内部更新 UIProgressView 的进度时 - 它没有得到更新。我可能需要实施一些代表吗?
初始化
progressView = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[progressView setFrame:CGRectOffset(CGRectMake(0, 0, 320, 8), 0, 1)];
[self.view addSubview:progressView];
然后我运行我的线程
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];
然后我尝试更新它
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]
waitUntilDone: YES];
progressView.progress += 0.5;.............
什么都没有……