下载文件时立即更新ULabel [英] Update ULabel immediately while downloading files
问题描述
我正在使用NSURLConnection下载文件.我的视图中有一个UILabel,它必须显示当前正在下载的文件. UILabel在开始和结束时都在更新.可以说我正在下载10个文件.我可以在开始下载之前和完成下载后设置标签文本.
I am using NSURLConnection to download the files . I have a UILabel in my View which has to display the currently downloading files. The UILabel is getting updated at the starting and the end. Lets say I am download 10 files. I am able to set the Label text before start downloading and after completing the download.
我可以理解,我尝试调用的方法未在主线程中运行,
I can understand that, the method which I am trying to call is not running in main thread,
所以我用下面的代码使它在主线程中运行,
So I have used the following code to make it run in the main thread ,
[_myHome performSelectorOnMainThread:@selector(updateLabel) withObject:nil waitUntilDone:YES];
方法是
- (void) updateLabel
{
_fileName.text =[NSString stringWithFormat:@"%@",fileName];
}
这似乎也不起作用.我在这里做错什么了吗?
This also seems to be not working. Am I doing anything wrong here ?
谁能告诉我如何立即更新标签?
Can anyone tell me how to update the label immediately ??
推荐答案
已解决:我使用NSNotificationCenter将通知发送到其他类,该类将立即更新标签.我尝试了performSelectorOnMainThread,即使updateProgress,performSelectorOnMainThread都在同一类中.
SOLVED : I used NSNotificationCenter to send notifications to other class, which will update the labels immediately. I tried with performSelectorOnMainThread, even if both the updateProgress, performSelectorOnMainThread is in same class.
任何未能解决该问题的原因都是最受欢迎的.
Any reasons for why it didn't worked out , is most welcome.
这篇关于下载文件时立即更新ULabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!