开发者

iPhone ABContact address book sorting.

How can I sort my address book by first n开发者_Go百科ame. I'm using the ABContact class.


First you need to get an array of all the contacts with the method :

CFArrayRef ABAddressBookCopyArrayOfAllPeople (
   ABAddressBookRef addressBook
);

Then you can create a mutable version of the array using :

CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(
                                          kCFAllocatorDefault,
                                          CFArrayGetCount(people),
                                          people
                                  );

And you can sort this array with :

CFArraySortValues(
        peopleMutable,
        CFRangeMake(0, CFArrayGetCount(peopleMutable)),
        (CFComparatorFunction) ABPersonComparePeopleByName,
        (void*) ABPersonGetSortOrdering()
);

You have a fully documented sample in the Address Book Programming guide

Hope this helps, Vincent

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜