gpt4 book ai didi

objective-c - Mojave 上的 NSProgressIndicator 问题

转载 作者:行者123 更新时间:2023-12-03 17:09:01 25 4
gpt4 key购买 nike

我在 sierra 操作系统上实现了 NSProgressIndicator,它在其上的应用程序中运行良好。但是,当我将应用程序移动到 high-sierra< 时进行测试mojave进度条根本不显示,但在 sierra

上运行良好

当单击应用程序中的按钮时,在按钮功能内,我启动了进度条,如下所示,

[_progressbar startAnimation:sender];
[_progressbar setHidden:false];

当我返回时,我将setHidden更改为true。那么,我哪里可能出错了?

更新:我尝试使用以下代码,

 //Create the block that we wish to run on a different thread.
void (^progressBlock)(void);
progressBlock = ^{

[_progressbar setDoubleValue:0.0];
[_progressbar startAnimation:sender];
[_progressbar setHidden:false];
// running = YES; // this is a instance variable


//NOTE: It is important to let all UI updates occur on the main thread,
//so we put the following UI updates on the main queue.
dispatch_async(dispatch_get_main_queue(), ^{

[_progressbar setNeedsDisplay:YES];
});

// Do some more hard work here...


}; //end of progressBlock
dispatch_queue_t queue = dispatch_get_global_queue(0,0);
dispatch_async(queue,progressBlock);

最佳答案

我在旧的 macOS 应用程序上注意到了这个问题,如果我没记错的话,这是在 High Sierra Beta 中首次测试后发生的,正如您刚刚发现的那样。

大多数用户界面 View 需要主线程来绘制或接收用户输入。但似乎在早期的 macOS 版本中,Apple 做了一些魔法,让 NSProgressIndicator 显示并动画化,即使主线程正忙于做其他工作。然后在最近的 macOS 版本(10.13?)中,这个魔力似乎已被删除。

在主线程上进行长时间运行的工作从来都不是一个好主意,因为它会使用户界面中的其他 View (从未具有 NSProgressIndicator 魔力)对用户没有响应。我认为苹果公司已经意识到了这一点,因为我们现在都是多线程的 Dispatch (也称为中央调度),是时候移除魔法了,这对他们来说可能很难维持。我一直发现它有点问题而且不可靠。

所以答案是,您需要从主线程获取进度指示器正在跟踪的任何工作。您可能会使用 dispatch_async()和 friend 们,尽管 NSOperation 和 NSOperationQueue 仍然可以工作并且也将完成这项工作。

关于objective-c - Mojave 上的 NSProgressIndicator 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56015982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com