Question

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

Was it helpful?

Solution

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.

OTHER TIPS

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //update your label 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top