我试图实现 UILocalizedIndexCollection,如 http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalizedIndexedCollat ion_Class/UILocalizedIndexedCollation.html
在获得用户的许可后,我得到了我的地址簿,这给了我一个 ABRecordRef 的数组,我有以下代码来尝试构建我需要的部分数组的数组。但是我不知道该为 collationStringSelectior 放什么。任何帮助都会很棒。
- (void)setListContent:(NSArray *)inListContent
{
if (listContent == inListContent) {
return;
}
[listContent release]; listContent = [inListContent retain];
NSMutableArray *sections = [NSMutableArray array];
UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];
for (int i=0;i < [listContent count];i++) {
ABRecordRef person=[listContent objectAtIndex:i];
NSLog(@"person name is ");
NSString* name = (NSString *)(ABRecordCopyCompositeName(person));
NSLog(name);
NSInteger section = [collation sectionForObject:person collationStringSelector:@selector(????)];
[sections addObject:person toSubarrayAtIndex:section];
}
NSInteger section = 0;
for (section = 0; section < [sections count]; section++) {
NSArray *sortedSubarray = [collation sortedArrayFromArray:[sections objectAtIndex:section]
collationStringSelector:@selector(name)];
[sections replaceObjectAtIndex:section withObject:sortedSubarray];
}
[sectionedListContent release];
sectionedListContent = [sections retain];
}