如何在iOS中按部分对通讯簿条目进行排序

时间:2012-11-17 00:29:32

标签: ios uitableview ios6 abrecord uilocalizedcollation

我试图实现UILocalizedIndexCollection,如上所示 http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalizedIndexedCollation_Class/UILocalizedIndexedCollation.html

我获得了用户的许可后得到了我的地址簿,它给了我一个ABRecordRef数组,我有以下代码来尝试构建我需要的节数组数组。但是我不知道要为collat​​ionStringSelectior放什么。任何帮助都会很棒。

- (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];
}

1 个答案:

答案 0 :(得分:1)

您应该使用以下代码:

NSInteger section = [collation sectionForObject:name collationStringSelector:@selector(self)];