您的位置:首页 > 其它

tableview 索引条问题

2015-08-13 17:31 176 查看
- (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;;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: