如何不让 NSSearchField 冻结?
我有一个 NSSearchField,其操作方法通过分析发送者参数(字符串)来完成所有搜索工作。
现在,搜索内容(提供大型数组)属于 CPU 密集型,这让我的搜索字段冻结了几秒钟。
在其他情况下,我会分离另一个 NSThread 以防止我的 GUI 冻结。但在这种情况下这是不可能的,因为每次用户在搜索字段中输入另一个字母时,我都会分离另一个(“搜索”)线程。
还有其他方法可以防止我的 NSSearchField 冻结吗?
顺便说一句:我的猜测是否定的,因为即使是开发者文档的搜索字段也一直冻结:)
I've got a NSSearchField, whose action method does all the searching stuff, by analyzing the sender argument (string).
Now the searching stuff (feeding a large array) is kind of CPU intensive, which lets my search field freeze for some seconds.
In other cases i'd detach another NSThread to prevent my GUI from freezing. But in this case that is not possible, because I would detach another ("search") thread everytime the user enters another letter in the search field.
Is there another way of keeping my NSSearchField from freezing?
BTW: My guess is NO, because even the Developoer Documentation's seach field freezes all the time :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我用GCD。我使用异步队列,该作业定期检查当前的搜索模式是否与调用的模式相比发生了变化,如果发生了变化,则进行保释。这看起来效果很好。
I use GCD. I use an async queue, and the job periodically checks if the current search pattern has changed from what it was called with, and bails if it has. This seems to work quite well.
您不能使用
setSendsWholeSearchString:
来停止输入字母时的搜索吗?Can't you use
setSendsWholeSearchString:
to stop it searching as letters are typed?每次用户键入内容时设置一个 NSTimer。
如果已经设置了计时器,则使其无效或重新安排。
这样,无论用户输入的速度有多快,您都只会被要求每 N 秒刷新一次搜索。
Set an NSTimer every time the user types something.
If there's a timer already set, invalidate or reschedule it.
That way, you only get called upon to refresh the search every N seconds, however fast the user types.