setProgress:animated:not working(在HTML解析期间)

时间:2013-10-10 14:28:59

标签: iphone ios objective-c uiprogressview

我在TFHppleElement的帮助下从网站解析HTML数据。现在在for循环中解析期间我想更新progressView但它无法正常工作。为什么呢?

我的代码:

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

1 个答案:

答案 0 :(得分:0)

我是这样做的。所以它在后台进行解析,我可以更新UI。

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

        ...
        for (...) {

                for (...) {

                    ...
                }
        }
    }
});