The right letter combination of tableview: generate group index

Time:2021-3-3

When you use the iPhone address book, you will find that you can search by letter on the right side, which is very convenient to use. In fact, this function is very simple to use uitableview, as long as you implement a method of data source protocol and build an array of group titles. The contents of array elements and group titles may not be exactly the same. Uitableview is located according to the index of array elements and the index order of each group of data, rather than searching by contents.

#Pragma mark returns the index of each group of titles
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
    Nslog (@ "generate group index");
    NSMutableArray *indexs=[[NSMutableArray alloc]init];
    for(KCContactGroup *group in _contacts){
        [indexs addObject:group.name];
    }
    return indexs;
}

The results are as follows
The right letter combination of tableview: generate group index

The implementation sequence of the above key methods should be noted in uitableviewindex. Please see the following figure:
The right letter combination of tableview: generate group index

It is worth noting that the method of generating cells is not called all at once, but only the cells currently displayed on the interface will be produced, and other cells will be displayed when the user scrolls.