我可以从 Internet 下载 ZIP 文件。后处理在 connectionDidFinishLoading 中完成,并且工作正常,除了没有更新 UIView 元素。例如,我设置了 statusUpdate.text = @"Uncompressing file" 但直到 connectionDidFinishLoading 完成后才会出现更改。同样,UIProgressView 和 UIActivityIndicatorView 对象在此方法结束之前不会更新。
有没有办法从这个方法中强制更新 UIView?我尝试设置 [self.view setNeedsDisplay] 但这没有用。它似乎在主线程中运行。这里的所有其他命令都可以正常工作 - 唯一的问题是更新 UI。
谢谢!
更新:这是不更新 UIVIEW 的代码:
-(void)viewWillAppear:(BOOL)animated {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(processUpdate:) userInfo:nil repeats:YES];
downloadComplete = NO;
statusText.text = @"";
}
-(void)processUpdate:(NSTimer *)theTimer {
if (! downloadComplete) {
return;
}
[timer invalidate];
statusText.text = @"Processing update file.";
progress.progress = 0.0;
totalFiles = [newFiles count];
for (id fileName in newFiles) {
count++;
progress.progress = (float)count / (float)totalFiles;
// ... process code goes here ...
}
}
在 processUpdate 结束时,我设置 downloadComplete = YES。这构建和运行没有错误并按预期工作,除了在 processUpdate 完成之前 UIVIEW 中没有任何更新,然后所有内容立即更新。
感谢您一直以来的帮助!