我是一个全新的Mac程序员,我需要有关如何使用NSProgressIndicator的帮助.我已经查找了示例代码,但找不到任何有用的东西.
我想要做的是:
-(IBAction)startProgressBar:(id)sender; { //I want to make the bar update itself by the value of 1 until it is at the value of 100 //Example: add 1 to bar every second until it is full }
解决方法
我认为performSelector:withObject:afterDelay将在这里帮助你.
编写一个会增加进度条的方法.在该方法结束时,调用performSelector:withObject:afterDelay,在相同的方法上延迟1秒,直到条满.
您可能不需要将对象传递给该方法,因此您可以使用nil.
编辑
在你的情况下,我会建议这样的事情:
- (IBAction)startProgressBar:(id)sender { // Initialize the progress bar to go from 0 to 100 [progress setMinValue:0.0]; [progress setMaxValue:100.0]; [progress setDoubleValue:0.0]; // Start the auto-increment calls [self incrementProgressBar]; } - (void)incrementProgressBar { // Increment the progress bar value by 1 [progress incrementBy:1.0]; // If the progress bar hasn't reached 100 yet,then wait a second and call again if([progress doubleValue] < 100.0) [self performSelector:@selector(incrementProgressBar) withObject:nil afterDelay:1]; }