2

When implementing a view similar to an ABPeoplePickerNavigationController, I'm not able to sort the list very quickly. The native contacts app loads the list instantly. I'm dealing with 4000+ contacts, so keeping load times down is important. I can't use the ABPeoplePickerNavigationController because I need to do a lot of custom UI work.

I was using ABAddressBookCopyArrayOfAllPeople, then placing the people in UILocalizedIndexedCollation sections using sectionForObject and then sorting the sections using sortedArrayFromArray. For 4000 contacts, my time was about 8 seconds.

I then switched to using ABAddressBookCopyArrayOfAllSources and for every source, ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering and just appending each source's contacts to the unsorted array, then using the same UILocalizedIndexedCollation technique. This dropped the time down to about 5 seconds, I guess since the sections were mostly sorted already.

Is there any way to improve on this? Any techniques I'm not aware of? Can I somehow load an ABPeoplePickerNavigationController data source without the view and use that? Or is there a faster sorting method?

Thanks very much.

4

2 回答 2

0

Is there any way to improve on this?

It may help to realize that you'll never need to display 4000 names immediately. All you really need is the names for whatever section the user is looking at, and you can probably find and sort those names much more quickly. Let's say the user is viewing the A section initially, so maybe you use a predicate to pick out names starting with A. Out of 4000 names, perhaps 400 start with A, and that'll cut your sorting time down to a fraction of a second. You can continue fetching and sorting sections in the background.

The point is that it doesn't really matter how long it takes to sort all the records. What matters is how long it takes to put the records that the user wants on the screen.

于 2013-06-02T02:21:32.513 回答
0

where are those contacts stored in? Are they in CoreData?

I would use CoreData together with a NSFetchedResultsController, which handles everything, so that you don't have to care about loading times, because the NSFetchedResultsController loads just as much contacts as needed for the currently visible cells of your tableView.

I hope this helps you

Linard

于 2013-06-02T04:31:44.473 回答