我正在嘗試在每次迭代中更新循環中的UILabel文本,但它僅顯示最後一個值,是否需要花費時間來完成循環大約是30-50秒。以編程方式更新UILabel
下面是代碼:
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]];
[self setProgress:i/[topicNew count]];
[self.lbltest setText:@"Image Downloading..."];
self.lbltest.text =imageName;
//NSLog(@"sending %f",i/[topicNew count]);
//lblpercent.text = [NSString stringWithFormat:@"%d",i];
[lblpercent setText:[[NSString stringWithFormat:@"%.0f",i/[topicNew count]] stringByAppendingString:@"%"]];
//[self.view addSubview:viewalert];
[self updateLabel:self];
NSLog(@"%@,%d",imageName,i);
if(imageData != nil)
[imageData writeToFile:imagePath atomically:YES];
else
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:NULL];
NSMutableDictionary *newWord = [NSMutableDictionary dictionaryWithObjectsAndKeys:[new objectForKey:kWordTitleKey], kWordTitleKey, [new objectForKey:kWordDefinitionKey], kWordDefinitionKey, imagePath, kWordImagePathKey, appDelegate.subject,kSubjectKey,topicName,kTopicKey,[new objectForKey:kWordMemorizedKey], kWordMemorizedKey, nil];
[newTopic addObject:newWord];
}
回答一個問題是完全不可能的......沒有問題。 – marzapower 2011-05-09 12:32:49
順便說一下,您在哪裏定義了UILabel屬性?您是以編程方式還是通過Interface Builder生成它? – marzapower 2011-05-09 12:33:38
必須在這裏同意marzapower。在我看來,你有兩個問題:你只能得到標籤上的最後一個值,而不是所有的......並且你的循環花費很長時間才能完成。請正確定義您的問題,以便有幫助的人不必提出有關您問題的問題。 – Joetjah 2011-05-09 12:39:02