开发者

How to not get NSSearchField freezing?

I've got a NSSearchField, whose action method does all the searching st开发者_运维知识库uff, 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 :)


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.


Can't you use setSendsWholeSearchString: to stop it searching as letters are typed?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜