I have my main thread where I call a method which loads data (takes a while). I call this method with performSelectorInBackground and pass the delegate. The data loading method calls back regularly to update the progress, it calls a method in the same controller class that originally launched it in the background (the delegate). This method looks like:
-(void)loadingProgress:(float)progress{
NSLog(@"Progress %f", progress);
myProgressView.progress = progress;
}
So I know the method is being called and running because I get the log readout of the increasing progress values but the progress indicator doesn't move. Everything I have found has stated to make sure the main thread is free to update the view, but doesn't the fact that NSLog runs mean that it is free? What's going on?
you have to update userinterface elements on the main thread. And therefor you have to change your method a little bit, because you have to use objects when using performSelectorOnMainThread:withObject:waitUntilDone:
Your method should look like this:
-(void)loadingProgress:(NSNumber *)nProgress{
float progress = [nProgress floatValue];
NSLog(@"Progress %f", progress);
myProgressView.progress = progress;
}
And you call it with:
[delegate performSelectorOnMainThread:@selector(loadingProgress:) withObject:[NSNumber numberWithFloat:progress] waitUntilDone:NO];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With