search

Home  >  Q&A  >  body text

ios - 请教一个tableview 右侧索引实现的思路


我现在能实现这种效果, 但是如何我想让右侧的这些索引 不管数据源的数据如何都显示A-Z, 想iphone手机通讯录那样, 有什么思路吗

高洛峰高洛峰2887 days ago311

reply all(4)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:48:14

    This is officially supported.

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
        return @[@"A", @"B", @"C", @"D"……];
    }

    Can’t we just arrange all 26 letters here?

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:48:14

    It can be achieved. Check the UITableView Section Index related content and you should be able to find the answer you want.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:48:14

    You should modify your own data source, because the index label display number is calculated based on the array count of your data source;
    You give 26 arrays in your original data source, and then fill the data in the corresponding object;
    In this way, you can use the sectionIndexTitlesForTableView method to return an array of 26 English letters and it will be OK.

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:48:14

    //返回27,是a-z和#
    UILocalizedIndexedCollation *indexCollation = [UILocalizedIndexedCollation currentCollation];     
    [self.titleArray addObjectsFromArray:[indexCollation sectionTitles]];      

    reply
    0
  • Cancelreply