objective-c – 如何使用可可进度条?
发布时间:2020-12-14 17:45:44 所属栏目:百科 来源:网络整理
导读:我是一个全新的Mac程序员,我需要有关如何使用NSProgressIndicator的帮助.我已经查找了示例代码,但找不到任何有用的东西. 我想要做的是: -(IBAction)startProgressBar:(id)sender; { //I want to make the bar update itself by the value of 1 until it is
我是一个全新的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]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |