Label UIProgressView未准确显示进度

Label UIProgressView未准确显示进度,label,uilabel,uiprogressview,Label,Uilabel,Uiprogressview,我正在使用UIProgresView显示下载,并在标签中显示内容下载的百分比。该函数每次都在执行。当我显示进度值时,它会正确地显示在控制台中。但它不显示在屏幕上,它仅以0%和100%显示。我也在使用ASIHTTP框架 请帮忙 注释中的代码: for (float i=0; i< [topicNew count]; i++) { NSDictionary *new= [topicNew objectAtIndex:i]; NSString *imageName = [[[N

我正在使用UIProgresView显示下载,并在标签中显示内容下载的百分比。该函数每次都在执行。当我显示进度值时,它会正确地显示在控制台中。但它不显示在屏幕上,它仅以0%和100%显示。我也在使用ASIHTTP框架

请帮忙

注释中的代码:

for (float i=0; i< [topicNew count]; i++) 
{ 
   NSDictionary *new= [topicNew objectAtIndex:i]; 
   NSString *imageName = [[[NSString alloc] initWithFormat:@"%@.%@.%@.png", appDelegate.subject,topicNamed,[new objectForKey:kWordTitleKey]] autorelease]; 
   NSString *imagePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:imageName]; 
   NSData *imageData = [self ParsingImagePath:[new objectForKey:kWordImagePathKey]]; 
   [progressView setProgress:i/[topicNew count]]; 
   [lblpercent setText:[[NSString stringWithFormat:@"%.0f",i/[topicNew count]] stringByAppendingString:@"%"]];
for(浮点i=0;i<[topicNew count];i++)
{ 
NSDictionary*new=[topicNew objectAtIndex:i];
NSString*imageName=[[NSString alloc]initWithFormat:@“%@.%@.%@.png”,appDelegate.subject,topicNamed,[new objectForKey:kWordTitleKey]]自动删除];
NSString*imagePath=[[self-applicationDocumentsDirectory]stringByAppendingPathComponent:imageName];
NSData*imageData=[self-ParsingImagePath:[new-objectForKey:kWordImagePathKey]];
[progressView setProgress:i/[topicNew count]];
[lblpercent setText:[[NSString stringWithFormat:@“%.0f”,i/[topicNew count]]stringByAppendingString:@“%”];

…此处有更多代码…

看起来您正在线程锁定主线程。这意味着,您正在更新progressView,但主线程永远不会离开for循环以显示更新的更改,直到for循环完成,这时您的进度似乎设置为100%

您需要使用计时器(NSTimer)或某种后台线程来处理图像文件。然后,当您要更新进度时,需要从后台线程调用UIProgressView实例(例如,for循环的末尾)

并将更新的进度传递给progressView。请确保您没有直接从后台线程调用progressView,因为UIKit不是线程安全的。只能从主线程调用它,或者使用
performSelectorOnMainThread:withObject:waitUntilDOne:
方法调用它


希望这能让你直接进入正确的状态

给我们一些代码,我感觉你在0到100的范围内工作,而不是0到1,可能施法也是个问题。不,我在0到1之间使用。没有人知道这一点!没有代码,没有帮助,对不起,其他一切都是猜测。for(float I=0;I<[topicNew count];I++){NSDictionary*new=[topicNew objectAtIndex:i];NSString*imageName=[[NSString alloc]initWithFormat:@“%@.%@.%@.png”,appDelegate.subject,topicNamed,[new objectForKey:kWordTitleKey]]autorelease];NSString*imagePath=[[self-applicationDocumentsDirectory]stringByAppendingPathComponent:imageName];NSData*imageData=[self-ParsingImagePath:[new objectForKey:kWordImagePathKey]];[progressView setProgress:i/[topicNew count]];[lblpercent setText:[[NSString stringWithFormat:@“%.0f”,i/[topicNew count]]stringByAppendingString:@“%]”;
float p = i/[topicNew count];
[progressView performSelectorOnMainThread:@selector(setProgress:) 
   withObject:[NSNumber numberWithFloat:p]
   waitUntilDone:NO];