作者:渐我素小黑陈琼敏 | 来源:互联网 | 2023-07-29 17:24
PossibleDuplicate:NSProgressIndicatorprogresswithForloops?可能重复:NSProgressIndicator进展For循
Possible Duplicate:
NSProgressIndicator progress with For loops?
可能重复:NSProgressIndicator进展For循环?
I have a simple question this time (hopefully). I have an NSProgressIndicatorView (progress bar) and I want to update its value and a status label as a for loop runs:
这次我有一个简单的问题(希望如此)。我有一个NSProgressIndicatorView(进度条),我想更新它的值和状态标签作为for循环运行:
for(int i=0; i<[nameArr count]; i++)
{
NSString* str = [nameArr objectAtIndex:i];
[text setStringValue:str];
[status setStringValue:[NSString stringWithFormat:@"Processing names...%d of %ld",(i+1),[nameArr count]]];
[progress setDoubleValue:i];
}
This code works, but the status label and the progress bar do not update until the entire for loop has finished. I can watch things work as it runs if I send them as an NSLog
, so I assume there should be an easy way (without creating an NSOperation
) to similarly update my status label and progress bar as I go.
此代码有效,但状态标签和进度条在整个for循环完成之前不会更新。如果我将它们作为NSLog发送,我可以观察它的运行情况,因此我认为应该有一种简单的方法(无需创建NSOperation)来同样更新我的状态标签和进度条。
Any ideas?
有任何想法吗?
1 个解决方案