tableview 索引条问题

来源:互联网 发布:破解平台软件下载 编辑:程序博客网 时间:2024/06/08 14:24



- (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;;}


0 0
原创粉丝点击