objective-c - 如何使用 cocoa 进度条?

标签 objective-c xcode progress-bar

我是一名全新的 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];
}

关于objective-c - 如何使用 cocoa 进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9470113/

相关文章:

ios - Popover 并没有解雇自己

ios - 如何判断一个对象是否已经被释放

objective-c - 不同目标中的两个同名 Objective C 文件,由 Swift 类使用

Python PyQt4 进度条卡住 GUI

ios - 如何在 UITableView 中移动没有 NSIndexPath 的单元格?

ios - PerformSelector 可能会导致泄漏 - 更好的解决方案

c++ - 误报 : Undefined or garbage value returned to caller

mysql - 显示 Tornado 请求的进度

javascript - jQuery:如何从给定的标记生成进度条

ios - AFNetworking isConcurrent任务如何恢复或暂停