gpt4 book ai didi

iphone - UIProgressView 进度未更新

转载 作者:行者123 更新时间:2023-12-03 20:16:37 26 4
gpt4 key购买 nike

我有一个 UIProgressView 作为 subview 添加到 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;.............

什么也没有......

最佳答案

我在 iOS 5.0 上也遇到了同样的问题。似乎直到 5.0,您都可以从任何线程更新“progress”变量,但必须从主线程调用 setNeedsDisplay。从 5.0 及更高版本开始,您还必须在主线程中设置“进度”值。希望对大家有帮助。

关于iphone - UIProgressView 进度未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3822794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com