gpt4 book ai didi

objective-c - NSStatusItem 阻止 NSWindows 中的用户界面更新

转载 作者:行者123 更新时间:2023-12-03 16:58:10 25 4
gpt4 key购买 nike

我正在开发一个应用程序,该应用程序中有多个 NSWindows 和一个 StatusItem,以便在任何 NSWindows 未打开时访问它们。其中一些窗口不断用新的号码和状态更新其界面。问题是每当我单击系统状态栏中的 StatusItem 时,它都会阻止窗口上的更新,并且在关闭 StatusMenu 之前我看不到任何更新。

最佳答案

这是关于Run Loop Modes .

在主线程上运行的延迟操作通常安排为主运行循环的NSDefaultRunLoopMode,这意味着在菜单或模式对话框打开时不运行。您需要使用 NSRunLoopCommonModes 来代替,这将允许它们在默认模式和事件跟踪(菜单、对话框)模式下运行。

例如:

  • 如果您使用 NSTimer 来触发更新事件,而不是使用 scheduledTimerWithTimeInterval,请结合使用 timerWithTimeInterval[ [NSRunLoop currentRunLoop] addTimer:theTimer forMode:NSRunLoopCommonModes]

  • 如果您使用performSelectorOnMainThread:withObject:waitUntilDone:,请改用performSelectorOnMainThread:withObject:waitUntilDone:modes:,传递[NSArray arrayWithObject: NSRunLoopCommonModes] 用于 modes: 参数。

关于objective-c - NSStatusItem 阻止 NSWindows 中的用户界面更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13643603/

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