- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
// 有问题的写法
#pragma mark -- 创建 section
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return _sectionIndexArray;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
for (int i = 0; i < _letterPatientsGroupArray.count; i++) {
LetterPatients *letterPatients = [_letterPatientsGroupArray objectAtIndex:i];
if ((letterPatients.letterFirst > title) && i > 0) {
return i - 1;
}
// lab.text = [NSString stringWithFormat:@" %@",letterPatients.letterFirst];
}
return index;
}
// 正确
#pragma mark -- 创建 section
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return _sectionIndexArray;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
//初始化索引
for (int i = 0; i < [_letterPatientsGroupArray count]; i++) {
LetterPatients *info = _letterPatientsGroupArray[i];
if ([info.letterFirst isEqualToString:title]) {
return i;
}
}
return NSNotFound;;
}