Cocoa UI 元素未更新
我有一些 Cocoa UI 元素,它们与 NSView 对象中实例化的对象有出口连接,而该对象又由 NSViewController 放置在那里。这些元素(明确的进度条和文本标签)不会更新:尽管其值不断变化,但进度条是死的和空的,文本标签不会通过 [textLabel setHidden:NO] 取消隐藏,文本标签不会更改它的字符串。
我所知道的是:
- 绑定值和在代码中设置它们之间没有区别。无论哪种方式都没有改变。
- 我检查过插座连接。他们都在那里。
- 我尝试过 [X displayIfNeeded],其中 X 是 UI 对象本身、包含的 NSView 和主窗口。没有区别。
- [progressBar setUsesThreadedAnimation:YES] 没有区别。有趣的是,如果我在程序中查看进度条,_threadedAnimation 仍然是“否”。
- 保存所有这些出口并执行导入操作的对象位于 NSViewController 对象拥有的 NSOperationQueue 中。
谢谢!
编辑:按照建议,我调用了 [self PerformSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithInt:myObject] waitUntilDone:NO]。 (我也尝试过 waitUntilDone:YES。)它仍然没有更新。调试器清楚地显示 updateProgress: 发生在主线程中,所以我不知道缺少什么。
I have a few Cocoa UI elements with outlet connexions to an object instantiated within an NSView object, which is in turn put there by an NSViewController. These elements, a definite progress bar and a text label, are not updating: the progress bar is dead and empty despite having its value change constantly, the text label does not unhide through [textLabel setHidden:NO], the text label does not change its string.
What I know:
- There's no difference between binding values and setting them in code. Nothing changes either way.
- I've checked outlet connections. They're all there.
- I've tried [X displayIfNeeded], where X has been the UI objects themselves, the containing NSView, and the main window. No difference.
- [progressBar setUsesThreadedAnimation:YES] makes no difference. Interestingly, if I look at progressBar mid-program, _threadedAnimation is still NO.
- The object holding all these outlets and performing an import operation is in an NSOperationQueue owned by the NSViewController object.
Thanks!
EDIT: As suggested, I called [self performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithInt:myObject] waitUntilDone:NO]. (I've also tried waitUntilDone:YES.) It's still not updating. The debugger clearly shows updateProgress: taking place in the main thread, so I don't know what's missing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有 NSOperation 任务都在单独的线程中执行。不允许您从单独的线程修改 UI,因为 AppKit 不是线程安全的。您将需要重构代码,以便使用以下方法在主线程上执行任何修改用户界面的调用:
All
NSOperation
tasks are performed in separate threads. You are not allowed to modify the UI from a separate thread as AppKit is not thread-safe. You will need to refactor your code so that any calls that modify the user interface are performed on the main thread using the method: