Update ULabel immediately while downloading files

泄露秘密 提交于 2019-12-25 08:57:43

问题


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];

and method is

- (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 ??


回答1:


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.




回答2:


- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //update your label 
}


来源:https://stackoverflow.com/questions/11411373/update-ulabel-immediately-while-downloading-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!