-1

I parse HTML Data from a Website with the help of the TFHppleElement. Now during the parsing in the for loop I want to update the progressView but it isn't working. Why?

My Code:

ParseHTMLData.m

for (...) {

        ...
        for (...) {

                for (...) {

                    ...
                }
        }

            SecondViewController *svc = [[SecondViewController alloc] init];
            float prog = 0.9f; //For testing a fix value
            [svc setProgressAnimated:[NSNumber numberWithFloat:prog]];

    }

SecondViewController.m

-(void)setProgressAnimated: (NSNumber *)number;
{
    [self.progressView setProgress:[number floatValue] animated:YES];
}
iCode
  • 1,456
  • 1
  • 15
  • 26
  • Are you doing the parsing in a separate thread? Can you confirm that it is hitting the call to setProgressAnimated: and is actually reaching the function. – Thomas Denney Oct 10 '13 at 14:37
  • What do you mean with seperate thread? How can I do that? Multithreading? – iCode Oct 10 '13 at 14:39
  • 1
    It could be that Hpple is parsing the HTML in a separate NSOperationQueue (i.e. not on the main thread) to the main queue, which means that you can't do UI updates from it. Therefore you must executing your setProgress: method on the [NSOperationQueue mainQueue] – Thomas Denney Oct 10 '13 at 14:43
  • @ProgrammingThomas How can I do that? – iCode Oct 10 '13 at 15:41
  • [[NSOperationQueue mainQueue] addOperationWithBlock:^{ SecondViewController *svc = [[SecondViewController alloc] init]; float prog = 0.9f; //For testing a fix value [svc setProgressAnimated:[NSNumber numberWithFloat:prog]]; }]; – Christian Di Lorenzo Oct 11 '13 at 10:40

1 Answers1

0

I got working it by doing it like this. So it is parsing in the background and I can update the UI.

dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        for (...) {

        ...
        for (...) {

                for (...) {

                    ...
                }
        }
    }
});
iCode
  • 1,456
  • 1
  • 15
  • 26