在 iPhone 上按字母顺序对 ABRecord 进行排序
我正在使用以下代码检索联系人姓名:
for( int i = 0 ; i < n ; i++ )
{
Contact *c = [[Contact alloc] init];
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
NSString *firstName = (NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(ref, kABPersonLastNameProperty);
c.firstName = firstName; //[NSString stringWithFormat:@"%@ %@", firstName, lastName];
c.lastName = lastName;
[contacts addObject:c];
[c release];
}
有人知道按字母顺序排序此列表的方法吗?我读过有关 sortedArrayUsingSelector:@selector(compare:)
但我不知道它是如何工作的。
I'm retrieving contact names with this code:
for( int i = 0 ; i < n ; i++ )
{
Contact *c = [[Contact alloc] init];
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
NSString *firstName = (NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(ref, kABPersonLastNameProperty);
c.firstName = firstName; //[NSString stringWithFormat:@"%@ %@", firstName, lastName];
c.lastName = lastName;
[contacts addObject:c];
[c release];
}
Does anyone know a way of ordering this list alphabetically? I've read about sortedArrayUsingSelector:@selector(compare:)
but I have no idea how that is supposed to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此方法将让您尊重用户按名字或姓氏排序的偏好。
专业提示:将您要排序的名称部分加粗;否则,当您混合具有[没有名字,没有姓氏,名字和姓氏]的联系人时,会变得混乱
This method will let you respect the user's preferences for sorting by first or last name.
Pro-tip: Boldface the part of the name that you're sorting on; otherwise it gets confusing when you mix contacts who have [no first name, no last name, first and last name]