Best way to implement address book autocompletion on iPhone?

有些话、适合烂在心里 提交于 2019-12-13 21:16:50

问题


I'm wondering what is the best (fastest and simplest) way to have a textfield auto complete with iPhone's address book contacts information.

Would access the address book each time a key is pressed fast enough ? Or do I have to load everything in my own local database (CoreData typically) ? Another way would be to load everything in memory at each app launch. Any experience regarding the access speed of the adress book ?

ADDED: I'd like to avoid having to load a local copy of the address book content because it's not only more code to write but you also need to sync your local copy when address book is modified.


回答1:


For super fast character by character retrieval, the approach you need is called a Directed acyclic word graph.




回答2:


Would access the address book each time a key is pressed fast enough ?

Probably not for large books but test it an see. You could call ABAddressBookCopyPeopleWithName with each additional character and see what pops up. You would most likely need to require a minimum number of characters e.g. 3 before performing the search because otherwise you would get a lot of returns for each the first character.

However, I don't think there are functions for phone numbers and addresses.

The alternative would be to create a tree data structure with letters and numbers that would branch out to a leaf containing an ABRecordID of a particular AddressBook entry. Using Core Data relationships is a quick and easy way to do that. Of course, you would have to update your tree continuously.



来源:https://stackoverflow.com/questions/5230976/best-way-to-implement-address-book-autocompletion-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!