循环刷新窗口
我有一个在 Mac 上用 xcode/cocoa 编写的应用程序。 主窗口上的标签在每次出现 [label setStringValue] 的重循环时都会更改,但仅在循环结束时刷新。 我如何才能在每次出现时刷新它?
谢谢 !
I have an application written in xcode/cocoa on Mac.
A label on the main window is changed in every occurrence of a heavy loop with [label setStringValue], however it is refreshed only at the end of the loop.
How can I have it refreshed in each occurrence ?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该使用队列。 backgroundQueue 中的重循环和 mainQueue 中的 [label setStringValue] 。
例子:
You should use a queue. Your heavy loop in backgroundQueue and [label setStringValue] in mainQueue.
Example:
您的问题是您在主线程上完成工作(循环)。主线程负责更新UI,不能被阻塞!
您需要启动一个新线程来完成繁重的工作并更新主线程上的 UI。
您应该看看 GCD,这是一个很好的轻量级解决方案,或者看看 PerformSelector... 方法。
Your problem is that you do the work (the loop) on the main thread. The main thread is responsible for updating the UI and must not be blocked!
You need to start a new thread to do the heavy work and update your UI on the main thread.
You should have a look at GCD which is a good an lightweight solution for that or have a look at the performSelector... methods.