如何排序iphone联系簿? [英] how to sort iphone contact book?

查看:216
本文介绍了如何排序iphone联系簿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何按姓名& ;;排序(或检索已排序的数组)iphone联系簿。姓氏以编程方式??

How can i sort (or retrieve sorted array of ) an iphone contact book by first name & last name programmatically ??

任何帮助都将受到赞赏......!
谢谢

Any help will be well appreciated...! Thanks

推荐答案

致电 ABAddressBookCopyArrayOfAllPeople()获取地址簿中所有人员记录的数组。然后按照文档

Call ABAddressBookCopyArrayOfAllPeople() to get an array of all person records in the address book. Then follow the documentation:


要对一组人进行排序,请将函数CFArraySortValues与函数一起使用ABPersonComparePeopleByName作为比较器和ABPersonSortOrdering类型的上下文。用户所需的排序顺序(由ABPersonGetSortOrdering返回)通常是首选上下文。

To sort an array of people, use the function CFArraySortValues with the function ABPersonComparePeopleByName as the comparator and a context of the type ABPersonSortOrdering. The user’s desired sort order, as returned by ABPersonGetSortOrdering, is generally the preferred context.

以下代码清单显示了整个地址簿数据库的排序示例:

The following code listing shows an example of sorting the entire Address Book database:

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(
                                          kCFAllocatorDefault,
                                          CFArrayGetCount(people),
                                          people
                                  );

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

CFRelease(addressBook);
CFRelease(people);
CFRelease(peopleMutable);


这篇关于如何排序iphone联系簿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆