简体   繁体   中英

Updating the UI when using a serial queue

I am using a serial queue to do a background thread (block) for video processing. I want to update a UI component (specifically a progress bar). I've found that while I can interact with the UI, my progress bar is not updating with calls to setProgress (called from the block), until the thread has finished.

dispatch_queue_t dispatch_queue = dispatch_queue_create("somequeue", NULL);

    [somebody doSomethingOnQueue:dispatch_queue usingBlock:^{

        progressBar.progress = someFloat; //does not update

    }];

You should update the UI on the main dispatch queue:

[somebody doSomethingOnQueue:dispatch_queue usingBlock:^{
    …
    dispatch_async(dispatch_get_main_queue(), ^{
        progressBar.progress = someFloat;
    });
}];

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