How do I update a progress bar in Cocoa during a long running loop?

后端 未结 4 531
悲&欢浪女
悲&欢浪女 2020-12-29 00:17

I\'ve got a while loop, that runs for many seconds and that\'s why I want to update a progress bar (NSProgressIndicator) during that process, but it updates onl

4条回答
  •  离开以前
    2020-12-29 00:33

    This worked for me, which is a combination of answers from others that did not seem to work (for me at least) on their own:

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
      //do something
      dispatch_async(dispatch_get_main_queue(), ^{
        progressBar.progress = (double)x / (double)[stockList count];            
      });  
      //do something else
    });
    

提交回复
热议问题