【问题标题】:iOS7: How to implement Section Index like Contacts on iOS7?iOS7:如何在 iOS7 上实现像联系人这样的部分索引?
【发布时间】:2014-04-03 16:16:55
【问题描述】:

在 iOS7 中,Contact 应用的 Section Index 显示的索引较少。

例如,“A ● C ● E ... M ● P ● R...”

我知道这两种委托方法:

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex

但我不知道如何实现这么短的索引。谁能给个提示?

非常感谢!

--编辑--

看一下索引:“M ● P ● R...”,如果我从“M”滑动到“P”,tableView 会显示部分“M”,然后是“N”,然后是“O”,然后是“ P',这意味着它使用三个索引索引到 4 个部分。

--编辑--

好的,这种索引是自动生成的。

如果表格的边框不够大,无法显示索引,则索引显示为点状索引。

【问题讨论】:

    标签: ios objective-c uitableview ios7


    【解决方案1】:

    这是标准索引的自动行为。 Contacts 中的索引是包含所有字符的普通索引,但您使用的是 iPhone 4 或 4s,当空间不足时,一些字母会被替换为点。如果您使用 iPhone 5 或 5s 打开应用程序,您会看到所有字母。

    【讨论】:

    • 是的,我观察到了这种行为。但我想缩短 3.5 英寸屏幕的索引,就像 Contact 一样。
    • 这种索引是自动生成的。我在这方面想太多了。如果 dot 没有出现在索引中,则索引不够长,无法显示 dot。缩短tableView后,显示带有点的索引。
    【解决方案2】:

    这就是你要找的吗?嗯,我已经替换了每颗心的点;-D

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
        NSMutableArray *ma = [NSMutableArray arrayWithArray:@[@"A",@"♥",@"C",@"♥",@"E"]];
        [ma insertObject:UITableViewIndexSearch atIndex:0]; //add magnifier at top
        return ma; 
    }
    

    【讨论】:

    • 这不起作用,因为这个方法只返回一个长度== 5的索引。当我从A滑动到E时,tableView只显示前5个部分。而在联系人中,对于这样的索引:“M ● P ● R ...”,如果我从“M”滑动到“P”,tableView 会显示部分“M”,然后是“N”,然后是“O”,然后是“P” ',这意味着它使用三个索引索引到 4 个部分。
    • 这应该通过-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex管理
    • 但我不知道如何将更少的索引匹配到更多的部分。我读了这个方法的抽取,参数索引是在 sectionIndex 中选择的索引,返回的整数是 tableView 中部分的索引。怎么搭配?
    • 如果您有 A、B、C、D、E...Y、Z 部分(26 个部分),如果您在 sectionIndexTitlesForTableView 中返回一个包含 A、.、D、.、G 的数组,.,J... 当您从 D 滑动到 G 时,您将得到 atIndex = 3(对于 D)、4(对于点)、5(对于 G)。您必须返回 4(当 atIndex = 3 时)、5 或 6(当 atIndex = 4 时)、7(当 atIndex = 5 时)或 (int)((atIndex-1)*1.5)+1)。当然,你永远不会停留在 B、E、H、K...
    猜你喜欢
    • 2014-04-03
    • 2013-09-20
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    相关资源
    最近更新 更多