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 d开发者_如何学Cispatch_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;
});
}];
You can use performSelectorOnMainThread:withObject:waitUntilDone:
.
精彩评论