开发者

iPhone SDK - Search Bar Thread Synchronization Question

开发者 https://www.devze.com 2022-12-21 17:11 出处:网络
This is more of a high level \"how do you solve this type of problem\" type of question, as opposed to a \"why doesn\'t my code compile\" question.

This is more of a high level "how do you solve this type of problem" type of question, as opposed to a "why doesn't my code compile" question.

I've got a search bar within an iPhone application that searches my data just fine. However, i have the search triggered (handleSearchForTerm is called) after each keypress. This creates some lag.

I like the idea of having search results appear automatically, but I don't like that for larger datasets, the act of searching appears to interrupt user input.

Is this something I can't fix aside from making my search routine faster? Or, is there a better way to handle this?

One thought is that I'd like to be able to trigger a search only, say, 5开发者_高级运维00ms after a keypress (unless there has been another keypress in the meantime, then reset). Is that possible?

Thanks for any help.


You can use the performSelector:withObject:afterDelay to call the search routine after a delay of 500ms

EDIT (after your comment):

You can use cancelPreviousPerformRequestsWithTarget: selector: object: to cancel subsequent calls to the search routine

Ofcourse, you will need some kind of mechanism to identify if a search routine is currently in process. Use semaphores for that.

0

精彩评论

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