2

我试图实现 UILocalizedIndexCollection,如 http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalizedIndexedCollat ​​ion_Class/UILocalizedIndexedCollat​​ion.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];
}
4

1 回答 1

1

您应该使用以下代码:

NSInteger section = [collation sectionForObject:name collationStringSelector:@selector(self)];
于 2012-11-22T12:49:56.063 回答