iPhone – 索引像iOS联系人应用程序

我想创建一个像iOS联系人应用的视图,

Basically i want is,Vertical ABCDEFG.... which is located on right
side of this image,when user clicks on character M i want to
get character M How should i achieve this ? is there any iOS
control which gives me this `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];
    }
}

解决方法

您需要实现这两种方法:

// 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;

与相应的数据源:

例如,如果您有一个数组

`@"Cat",@"Mouse",@"Dog",@"Horse",@"Duck",@"Monkey"`

然后你将返回和sectionIndexTitlesForTableView数组:

`@[@"C",@"D",@"H",@"M"]`

因为@“Dog”和@“Duck”代表@“D”,@“Mouse”和@“Monkey”代表@“M”,依此类推.

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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...