UIView子类(自定义进度视图)直到为时已晚才显示

时间:2012-08-21 21:39:52

标签: ios networking user-interface uiview download

我希望在下载某些数据(同步)时看到进度,但我的UIView子类(自定义进度视图)在下载完成之前不会显示。这是一些代码:

self.progressView.hidden = NO;

// I would expect the progressView to show up now
// but it doesn't

int i = 0;
for (Something *something in someList) {
    if (something...) {
        i++;
        // do something


        // start downloading some data
        NSString *urlPath = [NSString stringWithFormat:@"somePath"];
        NSURL *aURL = [NSURL URLWithString:urlPath];

        NSData* responseData = [NSData aURL];

        // parse out the JSON data
        NSError* error = nil;
        NSArray* json = [NSJSONSerialization
                         JSONObjectWithData:responseData
                         options:kNilOptions
                         error:&error];

        for (NSDictionary *currentObject in json) {
            // do some stuff
        }
    }
}

// the progressView does show up here... why?

在所有下载完成后,我在下载任何内容之前更改为非隐藏的progressView会显示。为什么会这样?如何在所有下载内容之前显示progressView?

1 个答案:

答案 0 :(得分:1)

因为您的下载正在阻止主线程,否则UI可以使用该线程更新屏幕内容。解决方案:为所有网络产生新线程。