简体   繁体   中英

UIView subclass (custom progress view) doesn't show up until it's too late

I want to see progress while downloading some data (synchronously) but my UIView subclass (the custom progress view) doesn't show up until the download is finished. Here's some code:

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?

The progressView that I change to non-hidden BEFORE I download anything gets shown AFTER all download is done. Why is that so? And how can I show the progressView BEFORE all download stuff?

Because your download is blocking the main thread, using which the UI could otherwise update the contents of the screen. Solution: spawn a new thread for all the networking stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM