iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iPhone – 索引像iOS联系人应用程序大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想创建一个像iOS联系人应用的视图,

谢谢你的支持.

编辑

- (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”等)

大佬总结

以上是大佬教程为你收集整理的iPhone – 索引像iOS联系人应用程序全部内容,希望文章能够帮你解决iPhone – 索引像iOS联系人应用程序所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。