像iOS联系人应用程序索引

Kru*_*nal 6 iphone contacts ipad ios

我想创建一个视图,iOS联系app有,

基本上我想要的是,垂直ABCDEFG....位于此图像的右侧,当用户点击角色M我想要获得角色M 我应该如何实现这一目标?是否有任何iOS控件给我这个'ABCDEF ......?

谢谢你的支持.

编辑

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return [[NSArray arrayWithObject:UITableViewIndexSearch] arrayByAddingObjectsFromArray:
            [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]];
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    if (title == UITableViewIndexSearch)
    {
        CGRect searchBarFrame = self.searchDisplayController.searchBar.frame;
        [tableView scrollRectToVisible:searchBarFrame animated:YES];

        return -1;
    }
    else {
        UILocalizedIndexedCollation *currentCollation = [UILocalizedIndexedCollation currentCollation];
        NSLog(@"selected charecter=%ld",(long)[currentCollation sectionForSectionIndexTitleAtIndex:index]);
        return [currentCollation sectionForSectionIndexTitleAtIndex:index-1];
    }
}
Run Code Online (Sandbox Code Playgroud)

Dan*_*lea 12

您需要实现这两种方法:

// return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                    
// tell table which section corresponds to section title/index (e.g. "B",1))
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
Run Code Online (Sandbox Code Playgroud)

与相应的数据源:

例如,如果您有一个数组

`@"Cat", @"Mouse", @"Dog", @"Horse", @"Duck", @"Monkey"`
Run Code Online (Sandbox Code Playgroud)

然后你会返回和数组为sectionIndexTitlesForTableView:

`@[@"C", @"D", @"H", @"M"]`
Run Code Online (Sandbox Code Playgroud)

因为@"Dog"@"Duck"无二@"D",@"Mouse"@"Monkey"无二@"M"等.

当然,对于sectionForSectionIndexTitle,您返回该索引的相应索引.(1表示@"D",3表示@"M"等)